File: fopendev.c

package info (click to toggle)
syslinux 2%3A3.71%2Bdfsg-5
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 18,336 kB
  • ctags: 49,435
  • sloc: ansic: 188,623; asm: 12,943; pascal: 7,861; perl: 3,446; makefile: 1,968; sh: 771; python: 470; java: 324; xml: 14; php: 4
file content (43 lines) | stat: -rw-r--r-- 665 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/*
 * fopendev.c
 */

#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>

FILE *fopendev(const struct dev_info *dev, const char *mode)
{
  int flags = O_RDONLY;
  int plus = 0;
  int fd;

  while ( *mode ) {
    switch ( *mode ) {
    case 'r':
      flags = O_RDONLY;
      break;
    case 'w':
      flags = O_WRONLY|O_CREAT|O_TRUNC;
      break;
    case 'a':
      flags = O_WRONLY|O_CREAT|O_APPEND;
      break;
    case '+':
      plus = 1;
      break;
    }
    mode++;
  }

  if ( plus ) {
    flags = (flags & ~(O_RDONLY|O_WRONLY)) | O_RDWR;
  }

  fd = opendev(file, flags);

  if ( fd < 0 )
    return NULL;
  else
    return fdopen(fd, mode);
}