Adding upstream version 6.03~pre1+dfsg.
[syslinux-debian/hramrach.git] / com32 / lib / fopendev.c
blobcd2f00f829d45d362e273d8bc34c2e9fd0715643
1 /*
2 * fopendev.c
3 */
5 #include <stdio.h>
6 #include <unistd.h>
7 #include <fcntl.h>
9 FILE *fopendev(const struct dev_info * dev, const char *mode)
11 int flags = O_RDONLY;
12 int plus = 0;
13 int fd;
15 while (*mode) {
16 switch (*mode) {
17 case 'r':
18 flags = O_RDONLY;
19 break;
20 case 'w':
21 flags = O_WRONLY | O_CREAT | O_TRUNC;
22 break;
23 case 'a':
24 flags = O_WRONLY | O_CREAT | O_APPEND;
25 break;
26 case '+':
27 plus = 1;
28 break;
30 mode++;
33 if (plus) {
34 flags = (flags & ~(O_RDONLY | O_WRONLY)) | O_RDWR;
37 fd = opendev(file, flags);
39 if (fd < 0)
40 return NULL;
41 else
42 return fdopen(fd, mode);