diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2016-03-04 10:36:08 +1300 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2016-03-04 10:36:51 +1300 |
commit | 4b49eed6098881fbde1f6c7728c1346fc8366979 (patch) | |
tree | 7c5a3d7ee9ec01e71ae1e6eea1f59533c0ca4c8d /cfn.c | |
parent | Clean up Makefile a bit (diff) | |
download | cat-4b49eed6098881fbde1f6c7728c1346fc8366979.tar.gz cat-4b49eed6098881fbde1f6c7728c1346fc8366979.zip |
Switch to fopen/fread etc
Not quite finished yet -- this does things with stdin I didn't expect,
like not printing it line-by-line, and requiring two EOFs for some
reason.
Diffstat (limited to 'cfn.c')
-rw-r--r-- | cfn.c | 13 |
1 files changed, 7 insertions, 6 deletions
@@ -3,10 +3,11 @@ /* Function opens and writes the contents of a named file to stdout; * effectively a wrapper around cfd() */ int cfn(const char *fn, void *buf) { - int fd; + FILE *fp; + int cfpr; /* Open the file to get a read-only file descriptor */ - if ((fd = open(fn, O_RDONLY)) == -1) { + if ((fp = fopen(fn, "r")) == NULL) { perror(__FUNCTION__); return -1; } @@ -14,15 +15,15 @@ int cfn(const char *fn, void *buf) { /* Pass the opened descriptor to cfd() to read it; we keep going even if * there are problems, because we need the descriptor closed even if we * couldn't read it */ - cfd(fd, buf); + cfpr = cfp(fp, buf); /* Close the descriptor, since we should now be done with it */ - if (close(fd) == -1) { + if (fclose(fp) != 0) { perror(__FUNCTION__); return -1; } - /* Done, assume success */ - return 0; + /* Done, return the result of the cfp() call */ + return cfpr; } |