}
static int pakfire_filelist_parse_line(PakfireFile* file, Pakfire pakfire,
- const char* line, unsigned int format) {
+ char* line, unsigned int format) {
unsigned int i = 0;
- char* data = strdupa(line);
- if (!data)
- return 1;
-
// Allocate file
int r = pakfire_file_create(file, pakfire);
if (r)
return r;
+ char buffer[PATH_MAX];
ssize_t size;
mode_t mode;
time_t time;
- unsigned int bytes_read = 0;
+ char* tok = NULL;
+ char* word = strtok_r(line, " ", &tok);
- char* word = strtok(data, " ");
while (word) {
if (format >= 4) {
switch (i) {
break;
// path
- #warning handle filenames with spaces
case 8:
- pakfire_file_set_path(*file, line + bytes_read);
+ pakfire_string_format(buffer, "/%s", word);
+ pakfire_file_set_path(*file, buffer);
break;
}
}
}
- // Count the bytes of the line that have been processed so far
- // (Skip all padding spaces)
- bytes_read += strlen(word) + 1;
- while (*(line + bytes_read) == ' ')
- bytes_read += 1;
-
- word = strtok(NULL, " ");
+ word = strtok_r(NULL, " ", &tok);
++i;
}
return r;
PakfireFile file = NULL;
- char* p = data;
-
- while (*p) {
- char* eol = strchr(p, '\n');
- if (eol)
- *eol = '\0';
+ char* tok = NULL;
- int r = pakfire_filelist_parse_line(&file, pakfire, p, format);
+ char* line = strtok_r(data, "\n", &tok);
+ while (line) {
+ int r = pakfire_filelist_parse_line(&file, pakfire, line, format);
if (r)
goto ERROR;
pakfire_file_unref(file);
// Move forward
- p += strlen(p) + 1;
+ line = strtok_r(NULL, "\n", &tok);
}
return 0;