Changeset 41504 in vbox for trunk/src/VBox/Runtime
- Timestamp:
- May 30, 2012 6:40:48 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/r3/stream.cpp
r40304 r41504 922 922 923 923 924 /** 925 * Reads a line from a file stream. 926 * A line ends with a '\\n', '\\0' or the end of the file. 927 * 928 * @returns iprt status code. 929 * @returns VINF_BUFFER_OVERFLOW if the buffer wasn't big enough to read an entire line. 930 * @param pStream The stream. 931 * @param pszString Where to store the line. 932 * The line will *NOT* contain any '\\n'. 933 * @param cchString The size of the string buffer. 934 */ 935 RTR3DECL(int) RTStrmGetLine(PRTSTREAM pStream, char *pszString, size_t cchString) 924 RTR3DECL(int) RTStrmGetLine(PRTSTREAM pStream, char *pszString, size_t cbString) 936 925 { 937 926 AssertReturn(RT_VALID_PTR(pStream) && pStream->u32Magic == RTSTREAM_MAGIC, VERR_INVALID_PARAMETER); 938 927 int rc; 939 if (pszString && c chString > 1)928 if (pszString && cbString > 1) 940 929 { 941 930 rc = pStream->i32Error; 942 931 if (RT_SUCCESS(rc)) 943 932 { 944 c chString--; /* save space for the terminator. */933 cbString--; /* save space for the terminator. */ 945 934 rtStrmLock(pStream); 946 935 for (;;) … … 951 940 int ch = fgetc(pStream->pFile); 952 941 #endif 942 943 /* Deal with \r\n sequences here. We'll return lone CR, but 944 treat CRLF as LF. */ 945 if (ch == '\r') 946 { 947 #ifdef HAVE_FWRITE_UNLOCKED /** @todo darwin + freebsd(?) has fgetc_unlocked but not fwrite_unlocked, optimize... */ 948 ch = fgetc_unlocked(pStream->pFile); 949 #else 950 ch = fgetc(pStream->pFile); 951 #endif 952 if (ch == '\n') 953 break; 954 955 *pszString++ = '\r'; 956 if (--cbString <= 0) 957 { 958 /* yeah, this is an error, we dropped a character. */ 959 rc = VERR_BUFFER_OVERFLOW; 960 break; 961 } 962 } 963 964 /* Deal with end of file. */ 953 965 if (ch == EOF) 954 966 { … … 975 987 break; 976 988 } 977 if (ch == '\0' || ch == '\n' || ch == '\r') 989 990 /* Deal with null terminator and (lone) new line. */ 991 if (ch == '\0' || ch == '\n') 978 992 break; 993 994 /* No special character, append it to the return string. */ 979 995 *pszString++ = ch; 980 if (--c chString <= 0)996 if (--cbString <= 0) 981 997 { 982 998 rc = VINF_BUFFER_OVERFLOW;
Note:
See TracChangeset
for help on using the changeset viewer.