replace getline with fgets for portability
BUG= Review URL: https://codereview.appspot.com/7085058 git-svn-id: http://skia.googlecode.com/svn/trunk@7163 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
parent
6d29eda491
commit
18a48c3c1c
@ -43,6 +43,9 @@ bool sk_frewind(SkFILE*);
|
||||
|
||||
size_t sk_fread(void* buffer, size_t byteCount, SkFILE*);
|
||||
size_t sk_fwrite(const void* buffer, size_t byteCount, SkFILE*);
|
||||
|
||||
char* sk_fgets(char* str, int size, SkFILE* f);
|
||||
|
||||
void sk_fflush(SkFILE*);
|
||||
|
||||
int sk_fseek(SkFILE*, size_t, int);
|
||||
@ -54,12 +57,6 @@ bool sk_exists(const char *path);
|
||||
// Returns true if a directory exists at this path.
|
||||
bool sk_isdir(const char *path);
|
||||
|
||||
// Get a single line of input from a file. Returns -1 on failure.
|
||||
// passing NULL for lineptr will allocate memory for the line with
|
||||
// sk_malloc; make sure to use sk_free to get rid of it when you're
|
||||
// done.
|
||||
ptrdiff_t sk_getline(char **lineptr, size_t *n, SkFILE *stream);
|
||||
|
||||
// Have we reached the end of the file?
|
||||
int sk_feof(SkFILE *);
|
||||
|
||||
|
@ -41,19 +41,11 @@ SkFILE* sk_fopen(const char path[], SkFILE_Flags flags)
|
||||
return f;
|
||||
}
|
||||
|
||||
ptrdiff_t sk_getline(char **lineptr, size_t *n, SkFILE *f) {
|
||||
bool make_private_copy = (NULL == *lineptr);
|
||||
|
||||
ptrdiff_t ret = ::getline(lineptr, n, (FILE *) f);
|
||||
if (make_private_copy) {
|
||||
char *local_copy = (char *) sk_malloc_throw(strlen(*lineptr) + 1);
|
||||
::memcpy(local_copy, *lineptr, strlen(*lineptr));
|
||||
::free(*lineptr);
|
||||
*lineptr = local_copy;
|
||||
}
|
||||
return ret;
|
||||
char* sk_fgets(char* str, int size, SkFILE* f) {
|
||||
return ::fgets(str, size, (FILE *)f);
|
||||
}
|
||||
|
||||
|
||||
int sk_feof(SkFILE *f) {
|
||||
return ::feof((FILE *)f);
|
||||
}
|
||||
|
@ -16,29 +16,23 @@ SkRTConfRegistry::SkRTConfRegistry(): fConfs(100) {
|
||||
return;
|
||||
}
|
||||
|
||||
char *line = NULL;
|
||||
size_t n = 0;
|
||||
char line[1024];
|
||||
|
||||
while (!sk_feof(fp)) {
|
||||
if (line) {
|
||||
sk_free(line);
|
||||
}
|
||||
line = NULL;
|
||||
|
||||
if (sk_getline(&line, &n, fp) == -1) break;
|
||||
if (!sk_fgets(line, sizeof(line), fp)) {
|
||||
break;
|
||||
}
|
||||
|
||||
char *commentptr = strchr(line, '#');
|
||||
if (commentptr == line) {
|
||||
continue;
|
||||
}
|
||||
if (NULL != commentptr) {
|
||||
char *tmp = (char *) sk_malloc_throw(commentptr-line+1);
|
||||
strncpy(tmp, line, commentptr-line);
|
||||
sk_free(line);
|
||||
line = tmp;
|
||||
*commentptr = '\0';
|
||||
}
|
||||
|
||||
char sep[] = " \t";
|
||||
char sep[] = " \t\r\n";
|
||||
|
||||
char *keyptr = strtok(line, sep);
|
||||
if (!keyptr) {
|
||||
|
Loading…
Reference in New Issue
Block a user