Unified error output
This commit is contained in:
parent
37bb1bc062
commit
91bf2347d3
11
src/cat.c
11
src/cat.c
|
@ -21,6 +21,7 @@ typedef enum _OutputDelay {
|
||||||
* returns:
|
* returns:
|
||||||
* 0 successful
|
* 0 successful
|
||||||
* 2 an error occured */
|
* 2 an error occured */
|
||||||
|
static int _cat_error(char * message, int ret);
|
||||||
static void _cat_file(FILE * fp, OutputDelay od);
|
static void _cat_file(FILE * fp, OutputDelay od);
|
||||||
static int _cat(OutputDelay od, int argc, char * argv[])
|
static int _cat(OutputDelay od, int argc, char * argv[])
|
||||||
{
|
{
|
||||||
|
@ -40,8 +41,7 @@ static int _cat(OutputDelay od, int argc, char * argv[])
|
||||||
fp = stdin;
|
fp = stdin;
|
||||||
else if((fp = fopen(argv[i], "r")) == NULL)
|
else if((fp = fopen(argv[i], "r")) == NULL)
|
||||||
{
|
{
|
||||||
perror("fopen");
|
res = _cat_error(argv[i], 2);
|
||||||
res = 2;
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
_cat_file(fp, od);
|
_cat_file(fp, od);
|
||||||
|
@ -51,6 +51,13 @@ static int _cat(OutputDelay od, int argc, char * argv[])
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int _cat_error(char * message, int ret)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "%s", "cat: ");
|
||||||
|
perror(message);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
static int _write_nonbuf(int c);
|
static int _write_nonbuf(int c);
|
||||||
static int _write_buf(int c);
|
static int _write_buf(int c);
|
||||||
static void _cat_file(FILE * fp, OutputDelay od)
|
static void _cat_file(FILE * fp, OutputDelay od)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user