Code cleanup
This commit is contained in:
parent
88f7d838a3
commit
33bc3d04f1
13
src/cat.c
13
src/cat.c
|
@ -24,8 +24,9 @@ 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[])
|
||||||
{
|
{
|
||||||
int res = 0;
|
int ret = 0;
|
||||||
int i;
|
int i;
|
||||||
|
FILE * fp;
|
||||||
|
|
||||||
if(argc == 0)
|
if(argc == 0)
|
||||||
{
|
{
|
||||||
|
@ -34,20 +35,18 @@ static int _cat(OutputDelay od, int argc, char * argv[])
|
||||||
}
|
}
|
||||||
for(i = 0; i < argc; i++)
|
for(i = 0; i < argc; i++)
|
||||||
{
|
{
|
||||||
FILE * fp;
|
|
||||||
|
|
||||||
if(strcmp("-", argv[i]) == 0)
|
if(strcmp("-", argv[i]) == 0)
|
||||||
fp = stdin;
|
fp = stdin;
|
||||||
else if((fp = fopen(argv[i], "r")) == NULL)
|
else if((fp = fopen(argv[i], "r")) == NULL)
|
||||||
{
|
{
|
||||||
res = _cat_error(argv[i], 2);
|
ret = _cat_error(argv[i], 1);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
_cat_file(fp, od);
|
_cat_file(fp, od);
|
||||||
if(fp != stdin)
|
if(fp != stdin)
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
}
|
}
|
||||||
return res;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int _cat_error(char * message, int ret)
|
static int _cat_error(char * message, int ret)
|
||||||
|
@ -83,7 +82,7 @@ static int _write_nonbuf(int c)
|
||||||
/* usage */
|
/* usage */
|
||||||
static int _usage(void)
|
static int _usage(void)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Usage: cat [-u][file ...]\n\
|
fprintf(stderr, "%s", "Usage: cat [-u][file ...]\n\
|
||||||
-u write without delay\n");
|
-u write without delay\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -101,7 +100,7 @@ int main(int argc, char * argv[])
|
||||||
case 'u':
|
case 'u':
|
||||||
flagu = OD_NONE;
|
flagu = OD_NONE;
|
||||||
break;
|
break;
|
||||||
case '?':
|
default:
|
||||||
return _usage();
|
return _usage();
|
||||||
}
|
}
|
||||||
return _cat(flagu, argc - optind, &argv[optind]);
|
return _cat(flagu, argc - optind, &argv[optind]);
|
||||||
|
|
|
@ -36,7 +36,7 @@ static int _mkfifo_error(char * message, int ret)
|
||||||
/* usage */
|
/* usage */
|
||||||
static int _usage(void)
|
static int _usage(void)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Usage: mkfifo [-m mode] file...\n\
|
fprintf(stderr, "%s", "Usage: mkfifo [-m mode] file...\n\
|
||||||
-m create fifo with the specified mode value\n");
|
-m create fifo with the specified mode value\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -72,7 +72,7 @@ static int _pwd(pwd_flag pf)
|
||||||
/* usage */
|
/* usage */
|
||||||
static int _usage(void)
|
static int _usage(void)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Usage: pwd [-L|-P]\n\
|
fprintf(stderr, "%s", "Usage: pwd [-L|-P]\n\
|
||||||
-L avoid \".\" or \"..\" filenames\n\
|
-L avoid \".\" or \"..\" filenames\n\
|
||||||
-P avoid symbolic links\n");
|
-P avoid symbolic links\n");
|
||||||
return 1;
|
return 1;
|
||||||
|
|
|
@ -54,7 +54,7 @@ static int _rmdir_p(char * pathname)
|
||||||
/* usage */
|
/* usage */
|
||||||
static int _usage(void)
|
static int _usage(void)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Usage: rmdir [-p] dir...\n\
|
fprintf(stderr, "%s", "Usage: rmdir [-p] dir...\n\
|
||||||
-p remove all directories in a pathname\n");
|
-p remove all directories in a pathname\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,7 +38,7 @@ static int _uname(int m, int n, int r, int s, int v)
|
||||||
/* usage */
|
/* usage */
|
||||||
static int _usage(void)
|
static int _usage(void)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Usage: uname [-snrvma]\n\
|
fprintf(stderr, "%s", "Usage: uname [-snrvma]\n\
|
||||||
-s operating system name\n\
|
-s operating system name\n\
|
||||||
-n name of this node on the network\n\
|
-n name of this node on the network\n\
|
||||||
-r operating system release name\n\
|
-r operating system release name\n\
|
||||||
|
|
Loading…
Reference in New Issue
Block a user