cc [ flag ... ] file ... -lgen [ library ... ]
#include <libgen.h>
char *copylist(const char *filenm, off_t *szptr);
MT-Safe
Upon success, copylist() returns a pointer to the memory allocated. Otherwise it returns NULL if it has trouble finding the file, calling malloc(), or reading the file.
/* read "file" into buf */ off_t size; char *buf; buf = copylist("file", &size); if (buf) { for (i=0; i<size; i++) if (buf[i]) putchar(buf[i]); else putchar{’\n’); } } else { fprintf(stderr, "%s: Copy failed for "file".\n", argv[0]); exit (1); }
When compiling multi-thread applications, the _REENTRANT flag must be defined on the compile line. This flag should only be used in multi-thread applications.