/src/wpantund/third_party/fgetln/fgetln.h
Line | Count | Source |
1 | | /* @file fgetln.h |
2 | | ** @author Robert Quattlebaum <darco@deepdarc.com> |
3 | | ** |
4 | | ** Copyright (C) 2012 Robert Quattlebaum |
5 | | ** |
6 | | ** Permission is hereby granted, free of charge, to any person |
7 | | ** obtaining a copy of this software and associated |
8 | | ** documentation files (the "Software"), to deal in the |
9 | | ** Software without restriction, including without limitation |
10 | | ** the rights to use, copy, modify, merge, publish, distribute, |
11 | | ** sublicense, and/or sell copies of the Software, and to |
12 | | ** permit persons to whom the Software is furnished to do so, |
13 | | ** subject to the following conditions: |
14 | | ** |
15 | | ** The above copyright notice and this permission notice shall |
16 | | ** be included in all copies or substantial portions of the |
17 | | ** Software. |
18 | | ** |
19 | | ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY |
20 | | ** KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE |
21 | | ** WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR |
22 | | ** PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS |
23 | | ** OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR |
24 | | ** OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR |
25 | | ** OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
26 | | ** SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
27 | | ** |
28 | | ** ------------------------------------------------------------------- |
29 | | ** |
30 | | ** This is a simple implementation of the BSD function `fgetln()`, |
31 | | ** for use on operating systems which do not have a copy. |
32 | | ** |
33 | | ** Man page URL: <http://www.openbsd.org/cgi-bin/man.cgi?query=fgetln> |
34 | | ** |
35 | | ** NOTE: This implementation is *NOT* thread safe! |
36 | | */ |
37 | | |
38 | | #define _WITH_GETLINE 1 |
39 | | |
40 | | #include <stdio.h> |
41 | | |
42 | | #if !defined(HAVE_FGETLN) |
43 | | #define HAVE_FGETLN \ |
44 | | defined(__DARWIN_C_LEVEL) && \ |
45 | | (__DARWIN_C_LEVEL >= __DARWIN_C_FULL) |
46 | | #endif |
47 | | |
48 | | #if !defined(fgetln) && !HAVE_FGETLN |
49 | | static char * |
50 | | fgetln_( |
51 | | FILE *stream, size_t *len |
52 | | ) |
53 | 29.4k | { |
54 | 29.4k | static char* linep = NULL; |
55 | 29.4k | static size_t linecap = 0; |
56 | 29.4k | ssize_t length = getline(&linep, &linecap, stream); |
57 | | |
58 | 29.4k | if (length == -1) { |
59 | 228 | free(linep); |
60 | 228 | linep = NULL; |
61 | 228 | linecap = 0; |
62 | 228 | length = 0; |
63 | 228 | } |
64 | 29.4k | if (len) |
65 | 29.4k | *len = length; |
66 | 29.4k | return linep; |
67 | 29.4k | } Unexecuted instantiation: FirmwareUpgrade.cpp:fgetln_(_IO_FILE*, unsigned long*) Line | Count | Source | 53 | 29.4k | { | 54 | 29.4k | static char* linep = NULL; | 55 | 29.4k | static size_t linecap = 0; | 56 | 29.4k | ssize_t length = getline(&linep, &linecap, stream); | 57 | | | 58 | 29.4k | if (length == -1) { | 59 | 228 | free(linep); | 60 | 228 | linep = NULL; | 61 | 228 | linecap = 0; | 62 | 228 | length = 0; | 63 | 228 | } | 64 | 29.4k | if (len) | 65 | 29.4k | *len = length; | 66 | 29.4k | return linep; | 67 | 29.4k | } |
|
68 | 29.4k | #define fgetln fgetln_ |
69 | | #endif |