>> Have you looked at the code? > Busybox source is currently on another machine, so it is a bit difficult > to look in.
http://git.busybox.net/busybox/tree/mailutils/mime.c > Seems you are doing a line buffer approach. I'm not familar > with libbb functions, but ther seems to be a function xmalloc_fgets ... > that should be the right one. Do something like the following ... > > // if skipping of empty lines at the start is required, we need a flag > got_data = 0; > // process all data of a single block in one loop > while ( (line = xmalloc_fgets(file)) != NULL) { > len = strlen(line); > // omit next line if xmalloc_fgets strips ´\n´ > if (len > 0 && line[len-1] == '\n') line[--len] = '\0'; > // strip of optional '\r' > if (len > 0 && line[len-1] == '\r') line[--len] = '\0'; > // check for empty line seqence > if (len == 0) { > // skip empty lines before data block (if required) > if (got_data == 0) continue; > // you got an empty line --> this is your end of data processing > best to do a return from function here > } > // remember we got data > got_data = 1; > // else you got a data line and have to process the lines data > (single line) > process your data here > } > // you get here on EOF of the pipe this may or may not be an error > // depending on specification > either end data processing or signal error > > > Best to put the complete loop for each block of data in a single function. > If required, you can put the fgets including stripping of \n and \r in > seperate function this makes things easier. > > int readline( file_t file, char** line ) > { > int l; > char* p = xmalloc_fgets(file); > if (p == NULL) return -1; > l = strlen(p); > if (l>0 && p[l-1] == '\n') p[--l] = '\0'; > if (l>0 && p[l-1] == '\r') p[--l] = '\0'; > *line = p; > return l; > } > > int len; > char* line; > while ( (len = readline(file,line)) > 0 ) { > if (len == 0) { > you got an empty line > } > process data of line > } > EOF or read error > > But please have a look, if something similar is already in libbb, else > the above readline function may be a libbb candidate. > > This will hopefully help ... > > --Vladimir _______________________________________________ busybox mailing list [email protected] http://lists.busybox.net/mailman/listinfo/busybox
