From ebaddd9ae89fbce54d25f289d1b7313a5a8fb47a Mon Sep 17 00:00:00 2001 From: "Michael I. Bushnell" Date: Sat, 12 Feb 1994 05:43:32 +0000 Subject: Formerly fdtests.c.~2~ --- fstests/fdtests.c | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) (limited to 'fstests') diff --git a/fstests/fdtests.c b/fstests/fdtests.c index 6e3de6d4..00cb5f13 100644 --- a/fstests/fdtests.c +++ b/fstests/fdtests.c @@ -23,21 +23,24 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ #include #include #include +#include -void +int main () { - int fd - char pathbuf[1024]; + int fd; + FILE *fp; + static const char string[] = "Did this get into the file?\n"; int written; stderr = stdout = mach_open_devstream (getdport (1), "w"); if (unlink (root, "CREATED") < 0 && errno != ENOENT) printf ("Error on unlink: %d\n", errno); + fd = open ("CREATED", O_WRITE | O_CREAT, 0666); if (fd < 0) - printf ("Error on open: %d\n", errno); + printf ("Error on poen: %d\n", errno); written = write (fd, string, strlen (string)); if (written < 0) printf ("Error on write: %d\n", errno); @@ -46,6 +49,24 @@ main () else if (sync ()) printf ("Error on sync: %d\n", errno); + + fp = fopen ("CREATED", "r"); + if (! fp) + perror ("fopen"); + else + { + char *line = NULL; + size_t len = 0; + ssize_t n = getline (&line, &len, fp); + if (n < 0) + perror ("getline"); + else + printf ("Read %d bytes: %.*s", n, line); + free (line); + } + printf ("All done.\n"); malloc (0); + + return 0; } -- cgit v1.2.3