Guido van Rossum | da5b8f2 | 2007-06-12 23:30:11 +0000 | [diff] [blame^] | 1 | /* File object implementation (what's left of it -- see io.py) */ |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 2 | |
Martin v. Löwis | 18e1655 | 2006-02-15 17:27:45 +0000 | [diff] [blame] | 3 | #define PY_SSIZE_T_CLEAN |
Guido van Rossum | c0b618a | 1997-05-02 03:12:38 +0000 | [diff] [blame] | 4 | #include "Python.h" |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 5 | |
Jack Jansen | 7b8c754 | 2002-04-14 20:12:41 +0000 | [diff] [blame] | 6 | #ifdef HAVE_GETC_UNLOCKED |
| 7 | #define GETC(f) getc_unlocked(f) |
| 8 | #define FLOCKFILE(f) flockfile(f) |
| 9 | #define FUNLOCKFILE(f) funlockfile(f) |
| 10 | #else |
| 11 | #define GETC(f) getc(f) |
| 12 | #define FLOCKFILE(f) |
| 13 | #define FUNLOCKFILE(f) |
| 14 | #endif |
| 15 | |
Guido van Rossum | da5b8f2 | 2007-06-12 23:30:11 +0000 | [diff] [blame^] | 16 | /* Newline flags */ |
Jack Jansen | 7b8c754 | 2002-04-14 20:12:41 +0000 | [diff] [blame] | 17 | #define NEWLINE_UNKNOWN 0 /* No newline seen, yet */ |
| 18 | #define NEWLINE_CR 1 /* \r newline seen */ |
| 19 | #define NEWLINE_LF 2 /* \n newline seen */ |
| 20 | #define NEWLINE_CRLF 4 /* \r\n newline seen */ |
Trent Mick | f29f47b | 2000-08-11 19:02:59 +0000 | [diff] [blame] | 21 | |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 22 | #ifdef __cplusplus |
| 23 | extern "C" { |
| 24 | #endif |
| 25 | |
Guido van Rossum | da5b8f2 | 2007-06-12 23:30:11 +0000 | [diff] [blame^] | 26 | /* External C interface */ |
Tim Peters | 59c9a64 | 2001-09-13 05:38:56 +0000 | [diff] [blame] | 27 | |
| 28 | PyObject * |
| 29 | PyFile_FromFile(FILE *fp, char *name, char *mode, int (*close)(FILE *)) |
| 30 | { |
Guido van Rossum | da5b8f2 | 2007-06-12 23:30:11 +0000 | [diff] [blame^] | 31 | PyObject *io, *stream, *nameobj; |
Guido van Rossum | 5397039 | 2007-06-12 00:28:30 +0000 | [diff] [blame] | 32 | |
| 33 | io = PyImport_ImportModule("io"); |
| 34 | if (io == NULL) |
| 35 | return NULL; |
Guido van Rossum | da5b8f2 | 2007-06-12 23:30:11 +0000 | [diff] [blame^] | 36 | stream = PyObject_CallMethod(io, "open", "is", fileno(fp), mode); |
| 37 | Py_DECREF(io); |
| 38 | if (stream == NULL) |
Guido van Rossum | 5397039 | 2007-06-12 00:28:30 +0000 | [diff] [blame] | 39 | return NULL; |
Guido van Rossum | da5b8f2 | 2007-06-12 23:30:11 +0000 | [diff] [blame^] | 40 | nameobj = PyUnicode_FromString(name); |
| 41 | if (nameobj == NULL) |
| 42 | PyErr_Clear(); |
| 43 | else { |
| 44 | if (PyObject_SetAttrString(stream, "name", nameobj) < 0) |
| 45 | PyErr_Clear(); |
| 46 | Py_DECREF(nameobj); |
Tim Peters | 59c9a64 | 2001-09-13 05:38:56 +0000 | [diff] [blame] | 47 | } |
Guido van Rossum | 5397039 | 2007-06-12 00:28:30 +0000 | [diff] [blame] | 48 | return stream; |
Tim Peters | 59c9a64 | 2001-09-13 05:38:56 +0000 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | PyObject * |
Fred Drake | fd99de6 | 2000-07-09 05:02:18 +0000 | [diff] [blame] | 52 | PyFile_GetLine(PyObject *f, int n) |
Guido van Rossum | 0bd2441 | 1991-04-04 15:21:57 +0000 | [diff] [blame] | 53 | { |
Guido van Rossum | 4ddf0a0 | 2001-01-07 20:51:39 +0000 | [diff] [blame] | 54 | PyObject *result; |
| 55 | |
Guido van Rossum | 3165fe6 | 1992-09-25 21:59:05 +0000 | [diff] [blame] | 56 | if (f == NULL) { |
Guido van Rossum | c0b618a | 1997-05-02 03:12:38 +0000 | [diff] [blame] | 57 | PyErr_BadInternalCall(); |
Guido van Rossum | 0bd2441 | 1991-04-04 15:21:57 +0000 | [diff] [blame] | 58 | return NULL; |
| 59 | } |
Guido van Rossum | 4ddf0a0 | 2001-01-07 20:51:39 +0000 | [diff] [blame] | 60 | |
Guido van Rossum | da5b8f2 | 2007-06-12 23:30:11 +0000 | [diff] [blame^] | 61 | { |
Guido van Rossum | c0b618a | 1997-05-02 03:12:38 +0000 | [diff] [blame] | 62 | PyObject *reader; |
| 63 | PyObject *args; |
Guido van Rossum | 4ddf0a0 | 2001-01-07 20:51:39 +0000 | [diff] [blame] | 64 | |
Guido van Rossum | c0b618a | 1997-05-02 03:12:38 +0000 | [diff] [blame] | 65 | reader = PyObject_GetAttrString(f, "readline"); |
Guido van Rossum | 3165fe6 | 1992-09-25 21:59:05 +0000 | [diff] [blame] | 66 | if (reader == NULL) |
| 67 | return NULL; |
| 68 | if (n <= 0) |
Raymond Hettinger | 8ae4689 | 2003-10-12 19:09:37 +0000 | [diff] [blame] | 69 | args = PyTuple_New(0); |
Guido van Rossum | 3165fe6 | 1992-09-25 21:59:05 +0000 | [diff] [blame] | 70 | else |
Guido van Rossum | c0b618a | 1997-05-02 03:12:38 +0000 | [diff] [blame] | 71 | args = Py_BuildValue("(i)", n); |
Guido van Rossum | 3165fe6 | 1992-09-25 21:59:05 +0000 | [diff] [blame] | 72 | if (args == NULL) { |
Guido van Rossum | c0b618a | 1997-05-02 03:12:38 +0000 | [diff] [blame] | 73 | Py_DECREF(reader); |
Guido van Rossum | 3165fe6 | 1992-09-25 21:59:05 +0000 | [diff] [blame] | 74 | return NULL; |
| 75 | } |
Guido van Rossum | c0b618a | 1997-05-02 03:12:38 +0000 | [diff] [blame] | 76 | result = PyEval_CallObject(reader, args); |
| 77 | Py_DECREF(reader); |
| 78 | Py_DECREF(args); |
Martin v. Löwis | af6a27a | 2003-01-03 19:16:14 +0000 | [diff] [blame] | 79 | if (result != NULL && !PyString_Check(result) && |
| 80 | !PyUnicode_Check(result)) { |
Guido van Rossum | c0b618a | 1997-05-02 03:12:38 +0000 | [diff] [blame] | 81 | Py_DECREF(result); |
Guido van Rossum | 3165fe6 | 1992-09-25 21:59:05 +0000 | [diff] [blame] | 82 | result = NULL; |
Guido van Rossum | c0b618a | 1997-05-02 03:12:38 +0000 | [diff] [blame] | 83 | PyErr_SetString(PyExc_TypeError, |
Guido van Rossum | 3165fe6 | 1992-09-25 21:59:05 +0000 | [diff] [blame] | 84 | "object.readline() returned non-string"); |
| 85 | } |
Guido van Rossum | 4ddf0a0 | 2001-01-07 20:51:39 +0000 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | if (n < 0 && result != NULL && PyString_Check(result)) { |
| 89 | char *s = PyString_AS_STRING(result); |
Martin v. Löwis | 18e1655 | 2006-02-15 17:27:45 +0000 | [diff] [blame] | 90 | Py_ssize_t len = PyString_GET_SIZE(result); |
Guido van Rossum | 4ddf0a0 | 2001-01-07 20:51:39 +0000 | [diff] [blame] | 91 | if (len == 0) { |
| 92 | Py_DECREF(result); |
| 93 | result = NULL; |
| 94 | PyErr_SetString(PyExc_EOFError, |
| 95 | "EOF when reading a line"); |
| 96 | } |
| 97 | else if (s[len-1] == '\n') { |
| 98 | if (result->ob_refcnt == 1) |
| 99 | _PyString_Resize(&result, len-1); |
| 100 | else { |
| 101 | PyObject *v; |
| 102 | v = PyString_FromStringAndSize(s, len-1); |
Guido van Rossum | c0b618a | 1997-05-02 03:12:38 +0000 | [diff] [blame] | 103 | Py_DECREF(result); |
Guido van Rossum | 4ddf0a0 | 2001-01-07 20:51:39 +0000 | [diff] [blame] | 104 | result = v; |
Guido van Rossum | 3165fe6 | 1992-09-25 21:59:05 +0000 | [diff] [blame] | 105 | } |
| 106 | } |
Guido van Rossum | 3165fe6 | 1992-09-25 21:59:05 +0000 | [diff] [blame] | 107 | } |
Martin v. Löwis | af6a27a | 2003-01-03 19:16:14 +0000 | [diff] [blame] | 108 | if (n < 0 && result != NULL && PyUnicode_Check(result)) { |
| 109 | Py_UNICODE *s = PyUnicode_AS_UNICODE(result); |
Martin v. Löwis | 18e1655 | 2006-02-15 17:27:45 +0000 | [diff] [blame] | 110 | Py_ssize_t len = PyUnicode_GET_SIZE(result); |
Martin v. Löwis | af6a27a | 2003-01-03 19:16:14 +0000 | [diff] [blame] | 111 | if (len == 0) { |
| 112 | Py_DECREF(result); |
| 113 | result = NULL; |
| 114 | PyErr_SetString(PyExc_EOFError, |
| 115 | "EOF when reading a line"); |
| 116 | } |
| 117 | else if (s[len-1] == '\n') { |
| 118 | if (result->ob_refcnt == 1) |
| 119 | PyUnicode_Resize(&result, len-1); |
| 120 | else { |
| 121 | PyObject *v; |
| 122 | v = PyUnicode_FromUnicode(s, len-1); |
| 123 | Py_DECREF(result); |
| 124 | result = v; |
| 125 | } |
| 126 | } |
| 127 | } |
Guido van Rossum | 4ddf0a0 | 2001-01-07 20:51:39 +0000 | [diff] [blame] | 128 | return result; |
Guido van Rossum | 0bd2441 | 1991-04-04 15:21:57 +0000 | [diff] [blame] | 129 | } |
| 130 | |
Guido van Rossum | 3165fe6 | 1992-09-25 21:59:05 +0000 | [diff] [blame] | 131 | /* Interfaces to write objects/strings to file-like objects */ |
| 132 | |
| 133 | int |
Fred Drake | fd99de6 | 2000-07-09 05:02:18 +0000 | [diff] [blame] | 134 | PyFile_WriteObject(PyObject *v, PyObject *f, int flags) |
Guido van Rossum | 3165fe6 | 1992-09-25 21:59:05 +0000 | [diff] [blame] | 135 | { |
Guido van Rossum | c0b618a | 1997-05-02 03:12:38 +0000 | [diff] [blame] | 136 | PyObject *writer, *value, *args, *result; |
Guido van Rossum | 3165fe6 | 1992-09-25 21:59:05 +0000 | [diff] [blame] | 137 | if (f == NULL) { |
Guido van Rossum | c0b618a | 1997-05-02 03:12:38 +0000 | [diff] [blame] | 138 | PyErr_SetString(PyExc_TypeError, "writeobject with NULL file"); |
Guido van Rossum | 3165fe6 | 1992-09-25 21:59:05 +0000 | [diff] [blame] | 139 | return -1; |
| 140 | } |
Guido van Rossum | c0b618a | 1997-05-02 03:12:38 +0000 | [diff] [blame] | 141 | writer = PyObject_GetAttrString(f, "write"); |
Guido van Rossum | 3165fe6 | 1992-09-25 21:59:05 +0000 | [diff] [blame] | 142 | if (writer == NULL) |
| 143 | return -1; |
Martin v. Löwis | 2777c02 | 2001-09-19 13:47:32 +0000 | [diff] [blame] | 144 | if (flags & Py_PRINT_RAW) { |
| 145 | if (PyUnicode_Check(v)) { |
| 146 | value = v; |
| 147 | Py_INCREF(value); |
| 148 | } else |
| 149 | value = PyObject_Str(v); |
| 150 | } |
| 151 | else |
Walter Dörwald | 1ab8330 | 2007-05-18 17:15:44 +0000 | [diff] [blame] | 152 | value = PyObject_ReprStr8(v); |
Guido van Rossum | c600411 | 1993-11-05 10:22:19 +0000 | [diff] [blame] | 153 | if (value == NULL) { |
Guido van Rossum | c0b618a | 1997-05-02 03:12:38 +0000 | [diff] [blame] | 154 | Py_DECREF(writer); |
Guido van Rossum | c600411 | 1993-11-05 10:22:19 +0000 | [diff] [blame] | 155 | return -1; |
Guido van Rossum | 3165fe6 | 1992-09-25 21:59:05 +0000 | [diff] [blame] | 156 | } |
Raymond Hettinger | 8ae4689 | 2003-10-12 19:09:37 +0000 | [diff] [blame] | 157 | args = PyTuple_Pack(1, value); |
Guido van Rossum | e9eec54 | 1997-05-22 14:02:25 +0000 | [diff] [blame] | 158 | if (args == NULL) { |
Guido van Rossum | c0b618a | 1997-05-02 03:12:38 +0000 | [diff] [blame] | 159 | Py_DECREF(value); |
| 160 | Py_DECREF(writer); |
Guido van Rossum | d3f9a1a | 1995-07-10 23:32:26 +0000 | [diff] [blame] | 161 | return -1; |
| 162 | } |
Guido van Rossum | c0b618a | 1997-05-02 03:12:38 +0000 | [diff] [blame] | 163 | result = PyEval_CallObject(writer, args); |
| 164 | Py_DECREF(args); |
| 165 | Py_DECREF(value); |
| 166 | Py_DECREF(writer); |
Guido van Rossum | 3165fe6 | 1992-09-25 21:59:05 +0000 | [diff] [blame] | 167 | if (result == NULL) |
| 168 | return -1; |
Guido van Rossum | c0b618a | 1997-05-02 03:12:38 +0000 | [diff] [blame] | 169 | Py_DECREF(result); |
Guido van Rossum | 3165fe6 | 1992-09-25 21:59:05 +0000 | [diff] [blame] | 170 | return 0; |
| 171 | } |
| 172 | |
Guido van Rossum | 27a60b1 | 1997-05-22 22:25:11 +0000 | [diff] [blame] | 173 | int |
Tim Peters | c1bbcb8 | 2001-11-28 22:13:25 +0000 | [diff] [blame] | 174 | PyFile_WriteString(const char *s, PyObject *f) |
Guido van Rossum | 3165fe6 | 1992-09-25 21:59:05 +0000 | [diff] [blame] | 175 | { |
| 176 | if (f == NULL) { |
Guido van Rossum | 27a60b1 | 1997-05-22 22:25:11 +0000 | [diff] [blame] | 177 | /* Should be caused by a pre-existing error */ |
Fred Drake | fd99de6 | 2000-07-09 05:02:18 +0000 | [diff] [blame] | 178 | if (!PyErr_Occurred()) |
Guido van Rossum | 27a60b1 | 1997-05-22 22:25:11 +0000 | [diff] [blame] | 179 | PyErr_SetString(PyExc_SystemError, |
| 180 | "null file for PyFile_WriteString"); |
| 181 | return -1; |
Guido van Rossum | 3165fe6 | 1992-09-25 21:59:05 +0000 | [diff] [blame] | 182 | } |
Guido van Rossum | c0b618a | 1997-05-02 03:12:38 +0000 | [diff] [blame] | 183 | else if (!PyErr_Occurred()) { |
| 184 | PyObject *v = PyString_FromString(s); |
Guido van Rossum | 27a60b1 | 1997-05-22 22:25:11 +0000 | [diff] [blame] | 185 | int err; |
| 186 | if (v == NULL) |
| 187 | return -1; |
| 188 | err = PyFile_WriteObject(v, f, Py_PRINT_RAW); |
| 189 | Py_DECREF(v); |
| 190 | return err; |
Guido van Rossum | 3165fe6 | 1992-09-25 21:59:05 +0000 | [diff] [blame] | 191 | } |
Guido van Rossum | 74ba247 | 1997-07-13 03:56:50 +0000 | [diff] [blame] | 192 | else |
| 193 | return -1; |
Guido van Rossum | 3165fe6 | 1992-09-25 21:59:05 +0000 | [diff] [blame] | 194 | } |
Andrew M. Kuchling | 06051ed | 2000-07-13 23:56:54 +0000 | [diff] [blame] | 195 | |
| 196 | /* Try to get a file-descriptor from a Python object. If the object |
| 197 | is an integer or long integer, its value is returned. If not, the |
| 198 | object's fileno() method is called if it exists; the method must return |
| 199 | an integer or long integer, which is returned as the file descriptor value. |
| 200 | -1 is returned on failure. |
| 201 | */ |
| 202 | |
Guido van Rossum | da5b8f2 | 2007-06-12 23:30:11 +0000 | [diff] [blame^] | 203 | int |
| 204 | PyObject_AsFileDescriptor(PyObject *o) |
Andrew M. Kuchling | 06051ed | 2000-07-13 23:56:54 +0000 | [diff] [blame] | 205 | { |
| 206 | int fd; |
| 207 | PyObject *meth; |
| 208 | |
| 209 | if (PyInt_Check(o)) { |
| 210 | fd = PyInt_AsLong(o); |
| 211 | } |
| 212 | else if (PyLong_Check(o)) { |
| 213 | fd = PyLong_AsLong(o); |
| 214 | } |
| 215 | else if ((meth = PyObject_GetAttrString(o, "fileno")) != NULL) |
| 216 | { |
| 217 | PyObject *fno = PyEval_CallObject(meth, NULL); |
| 218 | Py_DECREF(meth); |
| 219 | if (fno == NULL) |
| 220 | return -1; |
Tim Peters | 86821b2 | 2001-01-07 21:19:34 +0000 | [diff] [blame] | 221 | |
Andrew M. Kuchling | 06051ed | 2000-07-13 23:56:54 +0000 | [diff] [blame] | 222 | if (PyInt_Check(fno)) { |
| 223 | fd = PyInt_AsLong(fno); |
| 224 | Py_DECREF(fno); |
| 225 | } |
| 226 | else if (PyLong_Check(fno)) { |
| 227 | fd = PyLong_AsLong(fno); |
| 228 | Py_DECREF(fno); |
| 229 | } |
| 230 | else { |
| 231 | PyErr_SetString(PyExc_TypeError, |
| 232 | "fileno() returned a non-integer"); |
| 233 | Py_DECREF(fno); |
| 234 | return -1; |
| 235 | } |
| 236 | } |
| 237 | else { |
| 238 | PyErr_SetString(PyExc_TypeError, |
| 239 | "argument must be an int, or have a fileno() method."); |
| 240 | return -1; |
| 241 | } |
| 242 | |
Guido van Rossum | ddefaf3 | 2007-01-14 03:31:43 +0000 | [diff] [blame] | 243 | if (fd == -1 && PyErr_Occurred()) |
| 244 | return -1; |
Andrew M. Kuchling | 06051ed | 2000-07-13 23:56:54 +0000 | [diff] [blame] | 245 | if (fd < 0) { |
| 246 | PyErr_Format(PyExc_ValueError, |
| 247 | "file descriptor cannot be a negative integer (%i)", |
| 248 | fd); |
| 249 | return -1; |
| 250 | } |
| 251 | return fd; |
| 252 | } |
Jack Jansen | 7b8c754 | 2002-04-14 20:12:41 +0000 | [diff] [blame] | 253 | |
Jack Jansen | 7b8c754 | 2002-04-14 20:12:41 +0000 | [diff] [blame] | 254 | /* |
| 255 | ** Py_UniversalNewlineFgets is an fgets variation that understands |
| 256 | ** all of \r, \n and \r\n conventions. |
| 257 | ** The stream should be opened in binary mode. |
| 258 | ** If fobj is NULL the routine always does newline conversion, and |
| 259 | ** it may peek one char ahead to gobble the second char in \r\n. |
| 260 | ** If fobj is non-NULL it must be a PyFileObject. In this case there |
| 261 | ** is no readahead but in stead a flag is used to skip a following |
| 262 | ** \n on the next read. Also, if the file is open in binary mode |
| 263 | ** the whole conversion is skipped. Finally, the routine keeps track of |
| 264 | ** the different types of newlines seen. |
| 265 | ** Note that we need no error handling: fgets() treats error and eof |
| 266 | ** identically. |
| 267 | */ |
| 268 | char * |
| 269 | Py_UniversalNewlineFgets(char *buf, int n, FILE *stream, PyObject *fobj) |
| 270 | { |
| 271 | char *p = buf; |
| 272 | int c; |
| 273 | int newlinetypes = 0; |
| 274 | int skipnextlf = 0; |
Tim Peters | 058b141 | 2002-04-21 07:29:14 +0000 | [diff] [blame] | 275 | |
Jack Jansen | 7b8c754 | 2002-04-14 20:12:41 +0000 | [diff] [blame] | 276 | if (fobj) { |
Guido van Rossum | da5b8f2 | 2007-06-12 23:30:11 +0000 | [diff] [blame^] | 277 | errno = ENXIO; /* What can you do... */ |
| 278 | return NULL; |
Jack Jansen | 7b8c754 | 2002-04-14 20:12:41 +0000 | [diff] [blame] | 279 | } |
| 280 | FLOCKFILE(stream); |
| 281 | c = 'x'; /* Shut up gcc warning */ |
| 282 | while (--n > 0 && (c = GETC(stream)) != EOF ) { |
| 283 | if (skipnextlf ) { |
| 284 | skipnextlf = 0; |
| 285 | if (c == '\n') { |
| 286 | /* Seeing a \n here with skipnextlf true |
| 287 | ** means we saw a \r before. |
| 288 | */ |
| 289 | newlinetypes |= NEWLINE_CRLF; |
| 290 | c = GETC(stream); |
| 291 | if (c == EOF) break; |
| 292 | } else { |
| 293 | /* |
| 294 | ** Note that c == EOF also brings us here, |
| 295 | ** so we're okay if the last char in the file |
| 296 | ** is a CR. |
| 297 | */ |
| 298 | newlinetypes |= NEWLINE_CR; |
| 299 | } |
| 300 | } |
| 301 | if (c == '\r') { |
| 302 | /* A \r is translated into a \n, and we skip |
| 303 | ** an adjacent \n, if any. We don't set the |
| 304 | ** newlinetypes flag until we've seen the next char. |
| 305 | */ |
| 306 | skipnextlf = 1; |
| 307 | c = '\n'; |
| 308 | } else if ( c == '\n') { |
| 309 | newlinetypes |= NEWLINE_LF; |
| 310 | } |
| 311 | *p++ = c; |
| 312 | if (c == '\n') break; |
| 313 | } |
| 314 | if ( c == EOF && skipnextlf ) |
| 315 | newlinetypes |= NEWLINE_CR; |
| 316 | FUNLOCKFILE(stream); |
| 317 | *p = '\0'; |
Guido van Rossum | da5b8f2 | 2007-06-12 23:30:11 +0000 | [diff] [blame^] | 318 | if ( skipnextlf ) { |
Jack Jansen | 7b8c754 | 2002-04-14 20:12:41 +0000 | [diff] [blame] | 319 | /* If we have no file object we cannot save the |
| 320 | ** skipnextlf flag. We have to readahead, which |
| 321 | ** will cause a pause if we're reading from an |
| 322 | ** interactive stream, but that is very unlikely |
| 323 | ** unless we're doing something silly like |
| 324 | ** execfile("/dev/tty"). |
| 325 | */ |
| 326 | c = GETC(stream); |
| 327 | if ( c != '\n' ) |
| 328 | ungetc(c, stream); |
| 329 | } |
| 330 | if (p == buf) |
| 331 | return NULL; |
| 332 | return buf; |
| 333 | } |
| 334 | |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 335 | #ifdef __cplusplus |
| 336 | } |
| 337 | #endif |