Home | History | Annotate | Download | only in sys
      1 /*
      2  * zfopen.c
      3  */
      4 
      5 #include <stdio.h>
      6 #include <unistd.h>
      7 #include <fcntl.h>
      8 #include <syslinux/zio.h>
      9 
     10 FILE *zfopen(const char *file, const char *mode)
     11 {
     12     int flags = O_RDONLY;
     13     int plus = 0;
     14     int fd;
     15 
     16     while (*mode) {
     17 	switch (*mode) {
     18 	case 'r':
     19 	    flags = O_RDONLY;
     20 	    break;
     21 	case 'w':
     22 	    flags = O_WRONLY | O_CREAT | O_TRUNC;
     23 	    break;
     24 	case 'a':
     25 	    flags = O_WRONLY | O_CREAT | O_APPEND;
     26 	    break;
     27 	case '+':
     28 	    plus = 1;
     29 	    break;
     30 	}
     31 	mode++;
     32     }
     33 
     34     if (plus) {
     35 	flags = (flags & ~(O_RDONLY | O_WRONLY)) | O_RDWR;
     36     }
     37 
     38     fd = zopen(file, flags, 0666);
     39 
     40     if (fd < 0)
     41 	return NULL;
     42     else
     43 	return fdopen(fd, mode);
     44 }
     45