Mercurial > libavformat.hg
annotate file.c @ 396:96f8086bc2ba libavformat
warning patrol
| author | mellum |
|---|---|
| date | Wed, 24 Mar 2004 23:32:48 +0000 |
| parents | c7a3987b4462 |
| children | 9cff946a8bb8 |
| rev | line source |
|---|---|
| 0 | 1 /* |
| 2 * Buffered file io for ffmpeg system | |
| 3 * Copyright (c) 2001 Fabrice Bellard | |
| 4 * | |
| 5 * This library is free software; you can redistribute it and/or | |
| 6 * modify it under the terms of the GNU Lesser General Public | |
| 7 * License as published by the Free Software Foundation; either | |
| 8 * version 2 of the License, or (at your option) any later version. | |
| 9 * | |
| 10 * This library is distributed in the hope that it will be useful, | |
| 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 13 * Lesser General Public License for more details. | |
| 14 * | |
| 15 * You should have received a copy of the GNU Lesser General Public | |
| 16 * License along with this library; if not, write to the Free Software | |
| 17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
| 18 */ | |
| 19 #include "avformat.h" | |
| 20 #include <fcntl.h> | |
| 21 #ifndef CONFIG_WIN32 | |
| 22 #include <unistd.h> | |
| 23 #include <sys/ioctl.h> | |
| 24 #include <sys/time.h> | |
| 25 #else | |
| 26 #include <io.h> | |
| 27 #define open(fname,oflag,pmode) _open(fname,oflag,pmode) | |
| 28 #endif /* CONFIG_WIN32 */ | |
| 29 | |
| 30 | |
| 31 /* standard file protocol */ | |
| 32 | |
| 33 static int file_open(URLContext *h, const char *filename, int flags) | |
| 34 { | |
| 35 int access; | |
| 36 int fd; | |
| 37 | |
| 3 | 38 strstart(filename, "file:", &filename); |
| 39 | |
|
364
0d74e8abcb3d
avio patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents:
332
diff
changeset
|
40 if (flags & URL_RDWR) { |
|
0d74e8abcb3d
avio patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents:
332
diff
changeset
|
41 access = O_CREAT | O_TRUNC | O_RDWR; |
|
0d74e8abcb3d
avio patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents:
332
diff
changeset
|
42 } else if (flags & URL_WRONLY) { |
| 0 | 43 access = O_CREAT | O_TRUNC | O_WRONLY; |
| 44 } else { | |
| 45 access = O_RDONLY; | |
| 46 } | |
|
332
e47e82c9baf2
cygwin fix and dont average interlaced MVs patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
22
diff
changeset
|
47 #if defined(CONFIG_WIN32) || defined(CONFIG_OS2) || defined(__CYGWIN__) |
| 0 | 48 access |= O_BINARY; |
| 49 #endif | |
| 50 fd = open(filename, access, 0666); | |
| 51 if (fd < 0) | |
| 52 return -ENOENT; | |
| 396 | 53 h->priv_data = (void *)(size_t)fd; |
| 0 | 54 return 0; |
| 55 } | |
| 56 | |
| 57 static int file_read(URLContext *h, unsigned char *buf, int size) | |
| 58 { | |
| 396 | 59 int fd = (size_t)h->priv_data; |
| 0 | 60 return read(fd, buf, size); |
| 61 } | |
| 62 | |
| 63 static int file_write(URLContext *h, unsigned char *buf, int size) | |
| 64 { | |
| 396 | 65 int fd = (size_t)h->priv_data; |
| 0 | 66 return write(fd, buf, size); |
| 67 } | |
| 68 | |
| 69 /* XXX: use llseek */ | |
| 70 static offset_t file_seek(URLContext *h, offset_t pos, int whence) | |
| 71 { | |
| 396 | 72 int fd = (size_t)h->priv_data; |
| 0 | 73 #ifdef CONFIG_WIN32 |
| 74 return _lseeki64(fd, pos, whence); | |
| 75 #else | |
| 76 return lseek(fd, pos, whence); | |
| 77 #endif | |
| 78 } | |
| 79 | |
| 80 static int file_close(URLContext *h) | |
| 81 { | |
| 396 | 82 int fd = (size_t)h->priv_data; |
| 0 | 83 return close(fd); |
| 84 } | |
| 85 | |
| 86 URLProtocol file_protocol = { | |
| 87 "file", | |
| 88 file_open, | |
| 89 file_read, | |
| 90 file_write, | |
| 91 file_seek, | |
| 92 file_close, | |
| 93 }; | |
| 94 | |
| 95 /* pipe protocol */ | |
| 96 | |
| 97 static int pipe_open(URLContext *h, const char *filename, int flags) | |
| 98 { | |
| 99 int fd; | |
| 100 | |
| 101 if (flags & URL_WRONLY) { | |
| 102 fd = 1; | |
| 103 } else { | |
| 104 fd = 0; | |
| 105 } | |
| 394 | 106 #if defined(CONFIG_WIN32) || defined(CONFIG_OS2) || defined(__CYGWIN__) |
| 107 setmode(fd, O_BINARY); | |
| 108 #endif | |
| 396 | 109 h->priv_data = (void *)(size_t)fd; |
| 0 | 110 return 0; |
| 111 } | |
| 112 | |
| 113 static int pipe_read(URLContext *h, unsigned char *buf, int size) | |
| 114 { | |
| 396 | 115 int fd = (size_t)h->priv_data; |
| 0 | 116 return read(fd, buf, size); |
| 117 } | |
| 118 | |
| 119 static int pipe_write(URLContext *h, unsigned char *buf, int size) | |
| 120 { | |
| 396 | 121 int fd = (size_t)h->priv_data; |
| 0 | 122 return write(fd, buf, size); |
| 123 } | |
| 124 | |
| 125 static int pipe_close(URLContext *h) | |
| 126 { | |
| 127 return 0; | |
| 128 } | |
| 129 | |
| 130 URLProtocol pipe_protocol = { | |
| 131 "pipe", | |
| 132 pipe_open, | |
| 133 pipe_read, | |
| 134 pipe_write, | |
| 135 NULL, | |
| 136 pipe_close, | |
| 137 }; |
