bb_get_[chomped]line_from_file wasn't descriptive enough.
Renaming...
This commit is contained in:
parent
372686bde7
commit
2d5ca60bfb
@ -1206,7 +1206,7 @@ static char **create_list(const char *filename)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
while ((line = bb_get_chomped_line_from_file(list_stream)) != NULL) {
|
while ((line = xmalloc_getline(list_stream)) != NULL) {
|
||||||
file_list = xrealloc(file_list, sizeof(char *) * (count + 2));
|
file_list = xrealloc(file_list, sizeof(char *) * (count + 2));
|
||||||
file_list[count] = line;
|
file_list[count] = line;
|
||||||
count++;
|
count++;
|
||||||
|
@ -523,7 +523,7 @@ static llist_t *append_file_list_to_list(llist_t *list)
|
|||||||
tmp = cur;
|
tmp = cur;
|
||||||
cur = cur->link;
|
cur = cur->link;
|
||||||
free(tmp);
|
free(tmp);
|
||||||
while ((line = bb_get_chomped_line_from_file(src_stream)) != NULL) {
|
while ((line = xmalloc_getline(src_stream)) != NULL) {
|
||||||
char *filename_ptr = last_char_is(line, '/');
|
char *filename_ptr = last_char_is(line, '/');
|
||||||
if (filename_ptr > line)
|
if (filename_ptr > line)
|
||||||
*filename_ptr = '\0';
|
*filename_ptr = '\0';
|
||||||
|
@ -50,7 +50,7 @@ static void cut_file(FILE * file)
|
|||||||
unsigned int linenum = 0; /* keep these zero-based to be consistent */
|
unsigned int linenum = 0; /* keep these zero-based to be consistent */
|
||||||
|
|
||||||
/* go through every line in the file */
|
/* go through every line in the file */
|
||||||
while ((line = bb_get_chomped_line_from_file(file)) != NULL) {
|
while ((line = xmalloc_getline(file)) != NULL) {
|
||||||
|
|
||||||
/* set up a list so we can keep track of what's been printed */
|
/* set up a list so we can keep track of what's been printed */
|
||||||
char * printed = xzalloc(strlen(line) * sizeof(char));
|
char * printed = xzalloc(strlen(line) * sizeof(char));
|
||||||
|
@ -126,7 +126,7 @@ int md5_sha1_sum_main(int argc, char **argv)
|
|||||||
pre_computed_stream = xfopen(file_ptr, "r");
|
pre_computed_stream = xfopen(file_ptr, "r");
|
||||||
}
|
}
|
||||||
|
|
||||||
while ((line = bb_get_chomped_line_from_file(pre_computed_stream)) != NULL) {
|
while ((line = xmalloc_getline(pre_computed_stream)) != NULL) {
|
||||||
char *filename_ptr;
|
char *filename_ptr;
|
||||||
|
|
||||||
count_total++;
|
count_total++;
|
||||||
|
@ -124,9 +124,9 @@ static struct sort_key *add_key(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#define GET_LINE(fp) (global_flags&FLAG_z) ? bb_get_chunk_from_file(fp,NULL) \
|
#define GET_LINE(fp) (global_flags&FLAG_z) ? bb_get_chunk_from_file(fp,NULL) \
|
||||||
: bb_get_chomped_line_from_file(fp)
|
: xmalloc_getline(fp)
|
||||||
#else
|
#else
|
||||||
#define GET_LINE(fp) bb_get_chomped_line_from_file(fp)
|
#define GET_LINE(fp) xmalloc_getline(fp)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Iterate through keys list and perform comparisons */
|
/* Iterate through keys list and perform comparisons */
|
||||||
|
@ -69,7 +69,7 @@ int uniq_main(int argc, char **argv)
|
|||||||
dups = 0;
|
dups = 0;
|
||||||
|
|
||||||
/* gnu uniq ignores newlines */
|
/* gnu uniq ignores newlines */
|
||||||
while ((s1 = bb_get_chomped_line_from_file(in)) != NULL) {
|
while ((s1 = xmalloc_getline(in)) != NULL) {
|
||||||
e1 = s1;
|
e1 = s1;
|
||||||
for (i=skip_fields ; i ; i--) {
|
for (i=skip_fields ; i ; i--) {
|
||||||
e1 = skip_whitespace(e1);
|
e1 = skip_whitespace(e1);
|
||||||
|
@ -18,7 +18,7 @@ static int read_stduu(FILE *src_stream, FILE *dst_stream)
|
|||||||
{
|
{
|
||||||
char *line;
|
char *line;
|
||||||
|
|
||||||
while ((line = bb_get_chomped_line_from_file(src_stream)) != NULL) {
|
while ((line = xmalloc_getline(src_stream)) != NULL) {
|
||||||
int length;
|
int length;
|
||||||
char *line_ptr = line;
|
char *line_ptr = line;
|
||||||
|
|
||||||
@ -140,7 +140,7 @@ int uudecode_main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Search for the start of the encoding */
|
/* Search for the start of the encoding */
|
||||||
while ((line = bb_get_chomped_line_from_file(src_stream)) != NULL) {
|
while ((line = xmalloc_getline(src_stream)) != NULL) {
|
||||||
int (*decode_fn_ptr)(FILE * src, FILE * dst);
|
int (*decode_fn_ptr)(FILE * src, FILE * dst);
|
||||||
char *line_ptr;
|
char *line_ptr;
|
||||||
FILE *dst_stream;
|
FILE *dst_stream;
|
||||||
|
@ -32,7 +32,7 @@ static unsigned int copy_lines(FILE *src_stream, FILE *dest_stream, const unsign
|
|||||||
|
|
||||||
while (src_stream && (i < lines_count)) {
|
while (src_stream && (i < lines_count)) {
|
||||||
char *line;
|
char *line;
|
||||||
line = bb_get_line_from_file(src_stream);
|
line = xmalloc_fgets(src_stream);
|
||||||
if (line == NULL) {
|
if (line == NULL) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -96,7 +96,7 @@ int patch_main(int argc, char **argv)
|
|||||||
ret = 0;
|
ret = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
patch_line = bb_get_line_from_file(patch_file);
|
patch_line = xmalloc_fgets(patch_file);
|
||||||
while (patch_line) {
|
while (patch_line) {
|
||||||
FILE *src_stream;
|
FILE *src_stream;
|
||||||
FILE *dst_stream;
|
FILE *dst_stream;
|
||||||
@ -115,14 +115,14 @@ int patch_main(int argc, char **argv)
|
|||||||
*/
|
*/
|
||||||
while (patch_line && strncmp(patch_line, "--- ", 4) != 0) {
|
while (patch_line && strncmp(patch_line, "--- ", 4) != 0) {
|
||||||
free(patch_line);
|
free(patch_line);
|
||||||
patch_line = bb_get_line_from_file(patch_file);
|
patch_line = xmalloc_fgets(patch_file);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Extract the filename used before the patch was generated */
|
/* Extract the filename used before the patch was generated */
|
||||||
original_filename = extract_filename(patch_line, patch_level);
|
original_filename = extract_filename(patch_line, patch_level);
|
||||||
free(patch_line);
|
free(patch_line);
|
||||||
|
|
||||||
patch_line = bb_get_line_from_file(patch_file);
|
patch_line = xmalloc_fgets(patch_file);
|
||||||
if (strncmp(patch_line, "+++ ", 4) != 0) {
|
if (strncmp(patch_line, "+++ ", 4) != 0) {
|
||||||
ret = 2;
|
ret = 2;
|
||||||
bb_error_msg("Invalid patch");
|
bb_error_msg("Invalid patch");
|
||||||
@ -166,7 +166,7 @@ int patch_main(int argc, char **argv)
|
|||||||
printf("patching file %s\n", new_filename);
|
printf("patching file %s\n", new_filename);
|
||||||
|
|
||||||
/* Handle each hunk */
|
/* Handle each hunk */
|
||||||
patch_line = bb_get_line_from_file(patch_file);
|
patch_line = xmalloc_fgets(patch_file);
|
||||||
while (patch_line) {
|
while (patch_line) {
|
||||||
unsigned int count;
|
unsigned int count;
|
||||||
unsigned int src_beg_line;
|
unsigned int src_beg_line;
|
||||||
@ -197,11 +197,11 @@ int patch_main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
hunk_offset_start = src_cur_line;
|
hunk_offset_start = src_cur_line;
|
||||||
|
|
||||||
while ((patch_line = bb_get_line_from_file(patch_file)) != NULL) {
|
while ((patch_line = xmalloc_fgets(patch_file)) != NULL) {
|
||||||
if ((*patch_line == '-') || (*patch_line == ' ')) {
|
if ((*patch_line == '-') || (*patch_line == ' ')) {
|
||||||
char *src_line = NULL;
|
char *src_line = NULL;
|
||||||
if (src_stream) {
|
if (src_stream) {
|
||||||
src_line = bb_get_line_from_file(src_stream);
|
src_line = xmalloc_fgets(src_stream);
|
||||||
if (!src_line) {
|
if (!src_line) {
|
||||||
hunk_error++;
|
hunk_error++;
|
||||||
break;
|
break;
|
||||||
|
@ -904,7 +904,7 @@ restart:
|
|||||||
if (rfile) {
|
if (rfile) {
|
||||||
char *line;
|
char *line;
|
||||||
|
|
||||||
while ((line = bb_get_chomped_line_from_file(rfile))
|
while ((line = xmalloc_getline(rfile))
|
||||||
!= NULL)
|
!= NULL)
|
||||||
append(line);
|
append(line);
|
||||||
xprint_and_close_file(rfile);
|
xprint_and_close_file(rfile);
|
||||||
@ -1099,7 +1099,7 @@ static void add_files_link(llist_t *opt_f)
|
|||||||
if (!opt_f) return;
|
if (!opt_f) return;
|
||||||
add_files_link(opt_f->link);
|
add_files_link(opt_f->link);
|
||||||
cmdfile = xfopen(opt_f->data, "r");
|
cmdfile = xfopen(opt_f->data, "r");
|
||||||
while ((line = bb_get_chomped_line_from_file(cmdfile)) != NULL) {
|
while ((line = xmalloc_getline(cmdfile)) != NULL) {
|
||||||
add_cmd(line);
|
add_cmd(line);
|
||||||
free(line);
|
free(line);
|
||||||
}
|
}
|
||||||
|
@ -123,7 +123,7 @@ static int grep_file(FILE *file)
|
|||||||
int idx = 0; /* used for iteration through the circular buffer */
|
int idx = 0; /* used for iteration through the circular buffer */
|
||||||
#endif /* ENABLE_FEATURE_GREP_CONTEXT */
|
#endif /* ENABLE_FEATURE_GREP_CONTEXT */
|
||||||
|
|
||||||
while ((line = bb_get_chomped_line_from_file(file)) != NULL) {
|
while ((line = xmalloc_getline(file)) != NULL) {
|
||||||
llist_t *pattern_ptr = pattern_head;
|
llist_t *pattern_ptr = pattern_head;
|
||||||
grep_list_data_t * gl;
|
grep_list_data_t * gl;
|
||||||
|
|
||||||
@ -280,7 +280,7 @@ static void load_regexes_from_file(llist_t *fopt)
|
|||||||
fopt = cur->link;
|
fopt = cur->link;
|
||||||
free(cur);
|
free(cur);
|
||||||
f = xfopen(ffile, "r");
|
f = xfopen(ffile, "r");
|
||||||
while ((line = bb_get_chomped_line_from_file(f)) != NULL) {
|
while ((line = xmalloc_getline(f)) != NULL) {
|
||||||
llist_add_to(&pattern_head,
|
llist_add_to(&pattern_head,
|
||||||
new_grep_list_data(line, PATTERN_MEM_A));
|
new_grep_list_data(line, PATTERN_MEM_A));
|
||||||
}
|
}
|
||||||
|
@ -230,8 +230,9 @@ extern void erase_mtab(const char * name);
|
|||||||
extern long *find_pid_by_name( const char* pidName);
|
extern long *find_pid_by_name( const char* pidName);
|
||||||
extern long *pidlist_reverse(long *pidList);
|
extern long *pidlist_reverse(long *pidList);
|
||||||
extern char *find_block_device(char *path);
|
extern char *find_block_device(char *path);
|
||||||
extern char *bb_get_line_from_file(FILE *file);
|
extern char *xmalloc_fgets(FILE *file);
|
||||||
extern char *bb_get_chomped_line_from_file(FILE *file);
|
/* Chops off '\n' from the end, unlike fgets: */
|
||||||
|
extern char *xmalloc_getline(FILE *file);
|
||||||
extern char *bb_get_chunk_from_file(FILE *file, int *end);
|
extern char *bb_get_chunk_from_file(FILE *file, int *end);
|
||||||
extern off_t bb_copyfd_size(int fd1, int fd2, off_t size);
|
extern off_t bb_copyfd_size(int fd1, int fd2, off_t size);
|
||||||
extern off_t bb_copyfd_eof(int fd1, int fd2);
|
extern off_t bb_copyfd_eof(int fd1, int fd2);
|
||||||
|
@ -48,7 +48,7 @@ char *bb_get_chunk_from_file(FILE * file, int *end)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Get line, including trailing \n if any */
|
/* Get line, including trailing \n if any */
|
||||||
char *bb_get_line_from_file(FILE * file)
|
char *xmalloc_fgets(FILE * file)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
@ -56,7 +56,7 @@ char *bb_get_line_from_file(FILE * file)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Get line. Remove trailing \n */
|
/* Get line. Remove trailing \n */
|
||||||
char *bb_get_chomped_line_from_file(FILE * file)
|
char *xmalloc_getline(FILE * file)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
char *c = bb_get_chunk_from_file(file, &i);
|
char *c = bb_get_chunk_from_file(file, &i);
|
||||||
|
@ -208,7 +208,7 @@ int dc_main(int argc, char **argv)
|
|||||||
char *line = NULL;
|
char *line = NULL;
|
||||||
char *cursor = NULL;
|
char *cursor = NULL;
|
||||||
char *token = NULL;
|
char *token = NULL;
|
||||||
while ((line = bb_get_chomped_line_from_file(stdin))) {
|
while ((line = xmalloc_getline(stdin))) {
|
||||||
cursor = line;
|
cursor = line;
|
||||||
len = number_of_tokens(line);
|
len = number_of_tokens(line);
|
||||||
for (i = 0; i < len; i++) {
|
for (i = 0; i < len; i++) {
|
||||||
|
@ -95,7 +95,7 @@ int makedevs_main(int argc, char **argv)
|
|||||||
printf("table=<stdin>\n");
|
printf("table=<stdin>\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
while ((line = bb_get_chomped_line_from_file(table))) {
|
while ((line = xmalloc_getline(table))) {
|
||||||
char type;
|
char type;
|
||||||
unsigned int mode = 0755;
|
unsigned int mode = 0755;
|
||||||
unsigned int major = 0;
|
unsigned int major = 0;
|
||||||
|
@ -138,7 +138,7 @@ static int getfileentry(FILE * fp, struct dns_entry *s)
|
|||||||
char *r, *name;
|
char *r, *name;
|
||||||
|
|
||||||
restart:
|
restart:
|
||||||
r = bb_get_line_from_file(fp);
|
r = xmalloc_fgets(fp);
|
||||||
if (!r)
|
if (!r)
|
||||||
return -1;
|
return -1;
|
||||||
while (*r == ' ' || *r == '\t') {
|
while (*r == ' ' || *r == '\t') {
|
||||||
|
@ -649,7 +649,7 @@ static struct interfaces_file_t *read_interfaces(const char *filename)
|
|||||||
|
|
||||||
f = xfopen(filename, "r");
|
f = xfopen(filename, "r");
|
||||||
|
|
||||||
while ((buf = bb_get_chomped_line_from_file(f)) != NULL) {
|
while ((buf = xmalloc_getline(f)) != NULL) {
|
||||||
char *buf_ptr = buf;
|
char *buf_ptr = buf;
|
||||||
|
|
||||||
firstword = next_word(&buf_ptr);
|
firstword = next_word(&buf_ptr);
|
||||||
|
@ -91,7 +91,7 @@ int nameif_main(int argc, char **argv)
|
|||||||
} else {
|
} else {
|
||||||
ifh = xfopen(fname, "r");
|
ifh = xfopen(fname, "r");
|
||||||
|
|
||||||
while ((line = bb_get_line_from_file(ifh)) != NULL) {
|
while ((line = xmalloc_fgets(ifh)) != NULL) {
|
||||||
char *line_ptr;
|
char *line_ptr;
|
||||||
size_t name_length;
|
size_t name_length;
|
||||||
|
|
||||||
|
@ -1205,7 +1205,7 @@ void load_history ( const char *fromfile )
|
|||||||
if (( fp = fopen ( fromfile, "r" ))) {
|
if (( fp = fopen ( fromfile, "r" ))) {
|
||||||
|
|
||||||
for ( hi = 0; hi < MAX_HISTORY; ) {
|
for ( hi = 0; hi < MAX_HISTORY; ) {
|
||||||
char * hl = bb_get_chomped_line_from_file(fp);
|
char * hl = xmalloc_getline(fp);
|
||||||
int l;
|
int l;
|
||||||
|
|
||||||
if(!hl)
|
if(!hl)
|
||||||
|
@ -21,7 +21,7 @@ static void bb_dump_addfile(char *name)
|
|||||||
|
|
||||||
fp = xfopen(name, "r");
|
fp = xfopen(name, "r");
|
||||||
|
|
||||||
while ((buf = bb_get_chomped_line_from_file(fp)) != NULL) {
|
while ((buf = xmalloc_getline(fp)) != NULL) {
|
||||||
p = skip_whitespace(buf);
|
p = skip_whitespace(buf);
|
||||||
|
|
||||||
if (*p && (*p != '#')) {
|
if (*p && (*p != '#')) {
|
||||||
|
@ -186,7 +186,7 @@ static llist_t *get_block_backed_filesystems(void)
|
|||||||
f = fopen(filesystems[i], "r");
|
f = fopen(filesystems[i], "r");
|
||||||
if (!f) continue;
|
if (!f) continue;
|
||||||
|
|
||||||
while ((buf = bb_get_chomped_line_from_file(f)) != 0) {
|
while ((buf = xmalloc_getline(f)) != 0) {
|
||||||
if (!strncmp(buf, "nodev", 5) && isspace(buf[5]))
|
if (!strncmp(buf, "nodev", 5) && isspace(buf[5]))
|
||||||
continue;
|
continue;
|
||||||
fs = buf;
|
fs = buf;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user