From: James McCann Newsgroups: comp.os.msdos.djgpp Subject: File system extensions -- write() doesn't work? Date: Thu, 06 Mar 1997 19:07:03 -0800 Organization: Wolfe Internet Access, L.L.C. Lines: 64 Message-ID: <331F8657.68B1707@junkmailwolfenet.com> NNTP-Posting-Host: sea-ts1-p70.wolfenet.com Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------69F4B1BE202C450B50DAB238" To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp This is a multi-part message in MIME format. --------------69F4B1BE202C450B50DAB238 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit The attached program shows behavior I did not expect. It installs a handler for file descriptors returned by __FSEXT_allocate_fd and installs the handler w/ FSEXT_set_function. When the write function is called, the handler is called only for the first write. Read and close work as expected, and if the write() calls are replaced w/ calls to _write(), the handler is called as expected. I am using the libc.a from djdev201.zip dated 10/31/96. Is this a bug, or am I doing something wrong? -- James McCann jmccann AT wolfenet DOT com jmccann AT scn DOT org --------------69F4B1BE202C450B50DAB238 Content-Type: text/plain; charset=us-ascii; name="fseerr.c" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="fseerr.c" /* --------------- cut here ------------------*/ #include #include #include int handler(__FSEXT_Fnumber f, int *rv, va_list args) { int fd = va_arg(args, int); fprintf(stderr, "calling handler, fd: %d: ", fd); switch(f){ case __FSEXT_write: fprintf(stderr, "write\n"); return 1; case __FSEXT_read: fprintf(stderr, "read\n"); return 1; case __FSEXT_close: fprintf(stderr, "close\n"); __FSEXT_set_function(fd, 0); _close(fd); return 1; default:fprintf(stderr, "huh?\n"); return 0; }/* switch(f) */ } main() { int fd[2]; FILE *f[2]; char j[] = "junk"; char b[10]; fd[0] = __FSEXT_alloc_fd(handler); fd[1] = __FSEXT_alloc_fd(handler); if(fd[0]<0 || fd[1]<0){ fprintf(stderr, "bad fd\n", exit(1));} read(fd[0], b, 1); /*_*/write(fd[0], j, 1); close(fd[0]); read(fd[1], b, 1); /*_*/write(fd[1], j, 1); close(fd[1]); f[0] = tmpfile(); f[1] = tmpfile(); if(!f[0] || !f[1]){ fprintf(stderr, "bad file *\n", exit(1));} fd[0] = fileno(f[0]); fd[1] = fileno(f[1]); if(fd[0]<0 || fd[1]<0){ fprintf(stderr, "bad fd\n", exit(1));} __FSEXT_set_function(fd[0], handler); __FSEXT_set_function(fd[1], handler); read(fd[0], b, 1); /*_*/write(fd[0], j, 1); read(fd[1], b, 1); /*_*/write(fd[1], j, 1); } /* ----------------- end ---------------------*/ --------------69F4B1BE202C450B50DAB238--