Mercurial > libavformat.hg
annotate file.c @ 2273:7eb456c4ed8a libavformat
Replace all occurrences of AVERROR_NOMEM with AVERROR(ENOMEM).
author | takis |
---|---|
date | Thu, 19 Jul 2007 15:21:30 +0000 |
parents | 28eb72f5208a |
children | 3dfa90f47d53 |
rev | line source |
---|---|
0 | 1 /* |
2 * Buffered file io for ffmpeg system | |
3 * Copyright (c) 2001 Fabrice Bellard | |
4 * | |
1358
0899bfe4105c
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
1171
diff
changeset
|
5 * This file is part of FFmpeg. |
0899bfe4105c
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
1171
diff
changeset
|
6 * |
0899bfe4105c
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
1171
diff
changeset
|
7 * FFmpeg is free software; you can redistribute it and/or |
0 | 8 * modify it under the terms of the GNU Lesser General Public |
9 * License as published by the Free Software Foundation; either | |
1358
0899bfe4105c
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
1171
diff
changeset
|
10 * version 2.1 of the License, or (at your option) any later version. |
0 | 11 * |
1358
0899bfe4105c
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
1171
diff
changeset
|
12 * FFmpeg is distributed in the hope that it will be useful, |
0 | 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 * Lesser General Public License for more details. | |
16 * | |
17 * You should have received a copy of the GNU Lesser General Public | |
1358
0899bfe4105c
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
1171
diff
changeset
|
18 * License along with FFmpeg; if not, write to the Free Software |
896
edbe5c3717f9
Update licensing information: The FSF changed postal address.
diego
parents:
885
diff
changeset
|
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
0 | 20 */ |
21 #include "avformat.h" | |
2193
5ce5fad0dfac
replace the uses of old string functions that Reimar missed
mru
parents:
1787
diff
changeset
|
22 #include "avstring.h" |
0 | 23 #include <fcntl.h> |
24 #include <unistd.h> | |
25 #include <sys/time.h> | |
26 | |
27 | |
28 /* standard file protocol */ | |
29 | |
30 static int file_open(URLContext *h, const char *filename, int flags) | |
31 { | |
32 int access; | |
33 int fd; | |
34 | |
2193
5ce5fad0dfac
replace the uses of old string functions that Reimar missed
mru
parents:
1787
diff
changeset
|
35 av_strstart(filename, "file:", &filename); |
3 | 36 |
364
0d74e8abcb3d
avio patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents:
332
diff
changeset
|
37 if (flags & URL_RDWR) { |
0d74e8abcb3d
avio patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents:
332
diff
changeset
|
38 access = O_CREAT | O_TRUNC | O_RDWR; |
0d74e8abcb3d
avio patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents:
332
diff
changeset
|
39 } else if (flags & URL_WRONLY) { |
0 | 40 access = O_CREAT | O_TRUNC | O_WRONLY; |
41 } else { | |
42 access = O_RDONLY; | |
43 } | |
2205
28eb72f5208a
Check for O_BINARY instead of a list of systems that need it
ramiro
parents:
2193
diff
changeset
|
44 #ifdef O_BINARY |
0 | 45 access |= O_BINARY; |
46 #endif | |
47 fd = open(filename, access, 0666); | |
48 if (fd < 0) | |
1787
eb16c64144ee
This fixes error handling for BeOS, removing the need for some ifdefs.
mmu_man
parents:
1596
diff
changeset
|
49 return AVERROR(ENOENT); |
396 | 50 h->priv_data = (void *)(size_t)fd; |
0 | 51 return 0; |
52 } | |
53 | |
54 static int file_read(URLContext *h, unsigned char *buf, int size) | |
55 { | |
396 | 56 int fd = (size_t)h->priv_data; |
0 | 57 return read(fd, buf, size); |
58 } | |
59 | |
60 static int file_write(URLContext *h, unsigned char *buf, int size) | |
61 { | |
396 | 62 int fd = (size_t)h->priv_data; |
0 | 63 return write(fd, buf, size); |
64 } | |
65 | |
66 /* XXX: use llseek */ | |
67 static offset_t file_seek(URLContext *h, offset_t pos, int whence) | |
68 { | |
396 | 69 int fd = (size_t)h->priv_data; |
0 | 70 return lseek(fd, pos, whence); |
71 } | |
72 | |
73 static int file_close(URLContext *h) | |
74 { | |
396 | 75 int fd = (size_t)h->priv_data; |
0 | 76 return close(fd); |
77 } | |
78 | |
79 URLProtocol file_protocol = { | |
80 "file", | |
81 file_open, | |
82 file_read, | |
83 file_write, | |
84 file_seek, | |
85 file_close, | |
86 }; | |
87 | |
88 /* pipe protocol */ | |
89 | |
90 static int pipe_open(URLContext *h, const char *filename, int flags) | |
91 { | |
92 int fd; | |
93 | |
94 if (flags & URL_WRONLY) { | |
95 fd = 1; | |
96 } else { | |
97 fd = 0; | |
98 } | |
2205
28eb72f5208a
Check for O_BINARY instead of a list of systems that need it
ramiro
parents:
2193
diff
changeset
|
99 #ifdef O_BINARY |
394 | 100 setmode(fd, O_BINARY); |
101 #endif | |
396 | 102 h->priv_data = (void *)(size_t)fd; |
605 | 103 h->is_streamed = 1; |
0 | 104 return 0; |
105 } | |
106 | |
107 static int pipe_read(URLContext *h, unsigned char *buf, int size) | |
108 { | |
396 | 109 int fd = (size_t)h->priv_data; |
0 | 110 return read(fd, buf, size); |
111 } | |
112 | |
113 static int pipe_write(URLContext *h, unsigned char *buf, int size) | |
114 { | |
396 | 115 int fd = (size_t)h->priv_data; |
0 | 116 return write(fd, buf, size); |
117 } | |
118 | |
119 static int pipe_close(URLContext *h) | |
120 { | |
121 return 0; | |
122 } | |
123 | |
124 URLProtocol pipe_protocol = { | |
125 "pipe", | |
126 pipe_open, | |
127 pipe_read, | |
128 pipe_write, | |
129 NULL, | |
130 pipe_close, | |
131 }; |