home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 2 BBS / 02-BBS.zip / sqdev200.zip / samples / shfopen.c < prev    next >
C/C++ Source or Header  |  1994-05-23  |  805b  |  38 lines

  1. /*# name=A fopen() function which uses the SH_DENYNONE sharing attribute
  2. */
  3.  
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <io.h>
  7. #include <fcntl.h>
  8. #include <sys/types.h>
  9. #include <sys/stat.h>
  10. #include <share.h>
  11. #include <errno.h>
  12. #include "compiler.h"
  13. #include "prog.h"
  14.  
  15. FILE * _fast shfopen(char *name,char *fpmode,int fdmode)
  16. {
  17.   FILE *fp;
  18.   int fd;
  19.   
  20.   fd=sopen(name, fdmode | ((fdmode & (O_APPEND | O_WRONLY)) ? O_CREAT : 0),
  21.            SH_DENYNONE, S_IREAD | S_IWRITE);
  22.   
  23.   if (fd==-1 && errno==ENOENT && (fdmode & (O_APPEND | O_WRONLY)))
  24.     fd=sopen(name, fdmode | (O_WRONLY | O_CREAT | O_TRUNC),
  25.              SH_DENYNONE, S_IREAD | S_IWRITE);
  26.   
  27.   if (fd==-1)
  28.     return NULL;
  29.   
  30.   if ((fp=fdopen(fd, fpmode))==NULL)
  31.     close(fd); 
  32.   
  33.   return fp;
  34. }
  35.  
  36.  
  37.  
  38.