diff options
author | Rob Landley <rob@landley.net> | 2012-03-19 19:19:21 -0500 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2012-03-19 19:19:21 -0500 |
commit | ee00a7f4587c1b75dedb71b5aa3d12608fb7b54c (patch) | |
tree | 1898173cb11a34f3565ea134286e1060f8b0e743 /toys | |
parent | 522d90613ae7dc728a98d3ce3b939b4ad9b30f25 (diff) | |
download | toybox-ee00a7f4587c1b75dedb71b5aa3d12608fb7b54c.tar.gz |
Remove "feature test macros", replace non-portable fdprintf() with standard fprintf().
Diffstat (limited to 'toys')
-rw-r--r-- | toys/count.c | 5 | ||||
-rw-r--r-- | toys/patch.c | 31 |
2 files changed, 21 insertions, 15 deletions
diff --git a/toys/count.c b/toys/count.c index acc0c69f..0ec3919d 100644 --- a/toys/count.c +++ b/toys/count.c @@ -23,13 +23,14 @@ void count_main(void) { uint64_t size = 0; int len; + char buf[32]; for (;;) { len = xread(0, toybuf, sizeof(toybuf)); if (!len) break; size += len; xwrite(1, toybuf, len); - fdprintf(2, "%"PRIu64" bytes\r", size); + xwrite(2, buf, sprintf(buf, "%"PRIu64" bytes\r", size)); } - fdprintf(2,"\n"); + xwrite(2, "\n", 1); } diff --git a/toys/patch.c b/toys/patch.c index 38c71941..95702ae6 100644 --- a/toys/patch.c +++ b/toys/patch.c @@ -75,11 +75,15 @@ static void do_line(void *data) { struct double_list *dlist = (struct double_list *)data; - if (TT.state>1 && *dlist->data != TT.state) - fdprintf(TT.state == 2 ? 2 : TT.fileout, - "%s\n", dlist->data+(TT.state>3 ? 1 : 0)); + if (TT.state>1 && *dlist->data != TT.state) { + char *s = dlist->data+(TT.state>3 ? 1 : 0); + int i = TT.state == 2 ? 2 : TT.fileout; - if (PATCH_DEBUG) fdprintf(2, "DO %d: %s\n", TT.state, dlist->data); + xwrite(i, s, strlen(s)); + xwrite(i, "\n", 1); + } + + if (PATCH_DEBUG) fprintf(stderr, "DO %d: %s\n", TT.state, dlist->data); free(dlist->data); free(data); @@ -96,7 +100,8 @@ static void fail_hunk(void) if (!TT.current_hunk) return; TT.current_hunk->prev->next = 0; - fdprintf(2, "Hunk %d FAILED %ld/%ld.\n", TT.hunknum, TT.oldline, TT.newline); + fprintf(stderr, "Hunk %d FAILED %ld/%ld.\n", + TT.hunknum, TT.oldline, TT.newline); toys.exitval = 1; // If we got to this point, we've seeked to the end. Discard changes to @@ -128,11 +133,11 @@ static int apply_one_hunk(void) for (plist = TT.current_hunk; plist; plist = plist->next) { if (plist->data[0]==' ') matcheof++; else matcheof = 0; - if (PATCH_DEBUG) fdprintf(2, "HUNK:%s\n", plist->data); + if (PATCH_DEBUG) fprintf(stderr, "HUNK:%s\n", plist->data); } matcheof = matcheof < TT.context; - if (PATCH_DEBUG) fdprintf(2,"MATCHEOF=%c\n", matcheof ? 'Y' : 'N'); + if (PATCH_DEBUG) fprintf(stderr,"MATCHEOF=%c\n", matcheof ? 'Y' : 'N'); // Loop through input data searching for this hunk. Match all context // lines and all lines to be removed until we've found the end of a @@ -155,19 +160,19 @@ static int apply_one_hunk(void) // Is this EOF? if (!data) { - if (PATCH_DEBUG) fdprintf(2, "INEOF\n"); + if (PATCH_DEBUG) fprintf(stderr, "INEOF\n"); // Does this hunk need to match EOF? if (!plist && matcheof) break; if (backwarn) - fdprintf(2,"Possibly reversed hunk %d at %ld\n", + fprintf(stderr, "Possibly reversed hunk %d at %ld\n", TT.hunknum, TT.linenum); // File ended before we found a place for this hunk. fail_hunk(); goto done; - } else if (PATCH_DEBUG) fdprintf(2, "IN: %s\n", data); + } else if (PATCH_DEBUG) fprintf(stderr, "IN: %s\n", data); check = dlist_add(&buf, data); // Compare this line with next expected line of hunk. @@ -186,7 +191,7 @@ static int apply_one_hunk(void) // recheck remaining buffered data for a new match. if (PATCH_DEBUG) - fdprintf(2, "NOT: %s\n", plist->data); + fprintf(stderr, "NOT: %s\n", plist->data); TT.state = 3; check = llist_pop(&buf); @@ -204,7 +209,7 @@ static int apply_one_hunk(void) check = buf; } else { if (PATCH_DEBUG) - fdprintf(2, "MAYBE: %s\n", plist->data); + fprintf(stderr, "MAYBE: %s\n", plist->data); // This line matches. Advance plist, detect successful match. plist = plist->next; if (!plist && !matcheof) goto out; @@ -257,7 +262,7 @@ void patch_main(void) if (strip || !patchlinenum++) { int len = strlen(patchline); if (patchline[len-1] == '\r') { - if (!strip) fdprintf(2, "Removing DOS newlines\n"); + if (!strip) fprintf(stderr, "Removing DOS newlines\n"); strip = 1; patchline[len-1]=0; } |