commit 5da6ee9ede9946858e4f3d4cffdd793f9e6e7ca7
parent 7a60fca51981e55c84ae6550c638bd19cd3a3f06
Author: qorg11 <qorg@vxempire.xyz>
Date: Thu, 15 Jul 2021 20:18:19 +0200
format
Diffstat:
33 files changed, 205 insertions(+), 194 deletions(-)
diff --git a/src/.clang-format b/src/.clang-format
@@ -50,7 +50,7 @@ BraceWrapping:
BreakBeforeBinaryOperators: None
BreakBeforeConceptDeclarations: true
BreakBeforeBraces: Mozilla
-BreakBeforeInheritanceComma: false
+BreakBeforeInheritanceComma: true
BreakInheritanceList: BeforeComma
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
@@ -122,7 +122,7 @@ PenaltyBreakTemplateDeclaration: 10
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 200
PenaltyIndentedWhitespace: 0
-PointerAlignment: Left
+PointerAlignment: Right
ReflowComments: true
SortIncludes: true
SortJavaStaticImport: Before
@@ -135,7 +135,7 @@ SpaceBeforeCaseColon: false
SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
-SpaceBeforeParens: ControlStatements
+SpaceBeforeParens: false
SpaceAroundPointerQualifiers: Default
SpaceBeforeRangeBasedForLoopColon: true
SpaceInEmptyBlock: false
@@ -143,7 +143,7 @@ SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
SpacesInConditionalStatement: false
-SpacesInContainerLiterals: true
+SpacesInContainerLiterals: false
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
diff --git a/src/cat.c b/src/cat.c
@@ -6,23 +6,23 @@
#include <unistd.h>
int
-cat(int fd, const char* filename)
+cat(int fd, const char *filename)
{
int c;
char buf[8192];
- if (filename[0] == '-' && filename[1] != 'u')
+ if(filename[0] == '-' && filename[1] != 'u')
fd = 0;
- if (fd != 0)
+ if(fd != 0)
fd = open(filename, O_RDONLY);
- if (fd == -1) {
+ if(fd == -1) {
fprintf(stderr, "error opening %s: %s\n", filename, strerror(errno));
return -1;
}
- while ((c = read(fd, buf, sizeof(buf))) > 0) {
- if (c == -1)
+ while((c = read(fd, buf, sizeof(buf))) > 0) {
+ if(c == -1)
return -1;
write(1, buf, c);
}
@@ -30,12 +30,12 @@ cat(int fd, const char* filename)
return 0;
}
int
-main(int argc, char* argv[])
+main(int argc, char *argv[])
{
getopt(argc, argv, "u");
- if (argc == optind)
+ if(argc == optind)
cat(0, "-");
- for (int i = optind; i < argc; i++)
+ for(int i = optind; i < argc; i++)
cat(1, argv[i]);
return 0;
diff --git a/src/chgrp.c b/src/chgrp.c
@@ -5,28 +5,28 @@
#include <unistd.h>
int
-main(int argc, char* argv[])
+main(int argc, char *argv[])
{
int c;
int follow_symlink;
- while ((c = getopt(argc, argv, "h")) != -1) {
- switch (c) {
+ while((c = getopt(argc, argv, "h")) != -1) {
+ switch(c) {
case 'h':
follow_symlink = 1;
break;
}
}
- if (argc == 1 || argc == 2) {
+ if(argc == 1 || argc == 2) {
fprintf(stderr, "usage: chgrp group file...\n");
return 1;
}
- struct group* group_data = getgrnam(argv[optind]);
+ struct group *group_data = getgrnam(argv[optind]);
gid_t gid = group_data->gr_gid;
- for (int i = optind + 1; i < argc; i++) {
- if (follow_symlink) {
- if (lchown(argv[i], gid, getuid()) == -1)
+ for(int i = optind + 1; i < argc; i++) {
+ if(follow_symlink) {
+ if(lchown(argv[i], gid, getuid()) == -1)
fprintf(stderr, "Error: %i = %s\n", errno, strerror(errno));
- } else if (chown(argv[i], gid, getuid()) == -1) {
+ } else if(chown(argv[i], gid, getuid()) == -1) {
fprintf(stderr, "Error: %i = %s\n", errno, strerror(errno));
}
}
diff --git a/src/chmod.c b/src/chmod.c
@@ -5,17 +5,17 @@
#include <sys/stat.h>
int
-main(int argc, char* argv[])
+main(int argc, char *argv[])
{
mode_t mode = atoi(argv[1]);
- for (int i = 2; i < argc; i++) {
+ for(int i = 2; i < argc; i++) {
int fd = chmod(argv[i], mode);
- mu if (fd == -1) fprintf(stderr,
- "Error setting %i on %s\n %i = %s",
- mode,
- argv[i],
- errno,
- strerror(errno));
+ mu if(fd == -1) fprintf(stderr,
+ "Error setting %i on %s\n %i = %s",
+ mode,
+ argv[i],
+ errno,
+ strerror(errno));
}
return 0;
diff --git a/src/chown.c b/src/chown.c
@@ -6,19 +6,19 @@
/* TODO: use strtok() to get the group */
int
-main(int argc, char* argv[])
+main(int argc, char *argv[])
{
- if (argc == 1) {
+ if(argc == 1) {
fprintf(stderr, "No command given\n");
return 1;
}
- const char* user = argv[1];
+ const char *user = argv[1];
- struct passwd* data = getpwnam(user);
+ struct passwd *data = getpwnam(user);
uid_t uid = data->pw_gid;
gid_t gid = data->pw_gid; /* Change this with the strtok() thing */
- for (int i = 2; i <= argc; i++) {
+ for(int i = 2; i <= argc; i++) {
chown(argv[i], uid, gid);
}
diff --git a/src/chroot.c b/src/chroot.c
@@ -4,9 +4,9 @@
/* UNTESTED */
int
-main(int argc, char* argv[])
+main(int argc, char *argv[])
{
- if (argc == 1) {
+ if(argc == 1) {
fprintf(stderr, "Missing operand\n");
return 1;
}
diff --git a/src/cp.c b/src/cp.c
@@ -5,19 +5,19 @@
#include <unistd.h>
int
-copy(const char* src, const char* dst)
+copy(const char *src, const char *dst)
{
int source = open(src, O_RDONLY);
int destination = creat(dst, 0644);
- if (destination == -1) {
+ if(destination == -1) {
fprintf(stderr,
"Error opening destination file: %i = %s\n",
errno,
strerror(errno));
return 1;
}
- if (source == -1) {
+ if(source == -1) {
fprintf(stderr,
"Error opening source file: %i = %s\n",
errno,
@@ -26,7 +26,7 @@ copy(const char* src, const char* dst)
}
int lines;
char buf[8912];
- while ((lines = read(source, buf, sizeof(buf))) > 0)
+ while((lines = read(source, buf, sizeof(buf))) > 0)
write(destination, buf, lines);
close(destination);
close(source);
@@ -34,10 +34,10 @@ copy(const char* src, const char* dst)
}
int
-main(int argc, char* argv[])
+main(int argc, char *argv[])
{
int fd;
- if (argc == 1) {
+ if(argc == 1) {
fprintf(stderr, "usage: cp source destination\n");
return 1;
} else
diff --git a/src/date.c b/src/date.c
@@ -5,7 +5,7 @@
#include <unistd.h>
int
-main(int argc, char* argv[])
+main(int argc, char *argv[])
{
int c;
int u = 0;
@@ -13,10 +13,10 @@ main(int argc, char* argv[])
time_t now;
now = time(NULL);
char FORMAT[256] = "%c";
- struct tm* timeinfo;
+ struct tm *timeinfo;
- while ((c = getopt(argc, argv, "u")) != -1) {
- switch (c) {
+ while((c = getopt(argc, argv, "u")) != -1) {
+ switch(c) {
case 'u':
u = 1;
break;
@@ -25,10 +25,10 @@ main(int argc, char* argv[])
timeinfo = localtime(&now);
- if (u)
+ if(u)
timeinfo = gmtime(&now);
- if (argc > optind && argv[optind][0] == '+') {
+ if(argc > optind && argv[optind][0] == '+') {
argv[optind]++;
strcpy(FORMAT, argv[optind]);
}
diff --git a/src/dirname.c b/src/dirname.c
@@ -2,10 +2,10 @@
#include <stdio.h>
int
-main(int argc, char* argv[])
+main(int argc, char *argv[])
{
- char* dir = dirname(argv[1]);
- if (dir == NULL) {
+ char *dir = dirname(argv[1]);
+ if(dir == NULL) {
fprintf(stderr, "%s", argv[0]);
return 1;
}
diff --git a/src/du.c b/src/du.c
@@ -3,26 +3,26 @@
#include <sys/stat.h>
int
-main(int argc, char* argv[])
+main(int argc, char *argv[])
{
int c;
int human_readable = 0;
struct stat file_data;
- while ((c = getopt(argc, argv, "h")) != -1) {
- switch (c) {
+ while((c = getopt(argc, argv, "h")) != -1) {
+ switch(c) {
case 'h':
human_readable = 1;
break;
}
}
- if (argc == optind) {
+ if(argc == optind) {
printf("no!\n");
return 1;
}
- for (int i = optind; i < argc; i++) {
+ for(int i = optind; i < argc; i++) {
stat(argv[i], &file_data);
- if (human_readable)
+ if(human_readable)
printf("%li\t %s", file_data.st_size * 1024, argv[i]);
else
printf("%li\t %s", file_data.st_size, argv[i]);
diff --git a/src/echo.c b/src/echo.c
@@ -2,21 +2,21 @@
#include <string.h>
int
-main(int argc, char* argv[])
+main(int argc, char *argv[])
{
int nflag;
- if (!strcmp(*++argv, "-n")) {
+ if(!strcmp(*++argv, "-n")) {
nflag = 1;
argv++;
}
- while (*argv) {
+ while(*argv) {
(void)fputs(*argv, stdout); /* Print argv */
- if (*++argv)
+ if(*++argv)
putchar(' '); /* If multiple things in argv, print a space
between them. */
}
- if (!nflag)
+ if(!nflag)
putchar('\n');
return 0;
}
diff --git a/src/exec.c b/src/exec.c
@@ -2,13 +2,13 @@
#include <unistd.h>
int
-main(int argc, char* argv[])
+main(int argc, char *argv[])
{
- if (argc == 1) {
+ if(argc == 1) {
fprintf(stderr, "what do you want to do?\n");
return 1;
}
- char* const argv2[1] = { argv[2] };
+ char *const argv2[1] = { argv[2] };
execv(argv[1], argv2);
return 0;
}
diff --git a/src/groups.c b/src/groups.c
@@ -5,19 +5,19 @@
#include <unistd.h>
int
-main(int argc, char* argv[])
+main(int argc, char *argv[])
{
- struct passwd* pwd;
- if (argc == 2)
+ struct passwd *pwd;
+ if(argc == 2)
pwd = getpwnam(argv[1]);
else
pwd = getpwuid(getuid());
int ngroups = 10;
- uid_t* groups = malloc(ngroups);
+ uid_t *groups = malloc(ngroups);
getgrouplist(pwd->pw_name, pwd->pw_gid, groups, &ngroups);
- struct group* gr;
- for (int i = 0; i < ngroups; i++) {
+ struct group *gr;
+ for(int i = 0; i < ngroups; i++) {
gr = getgrgid(groups[i]);
printf("%s ", gr->gr_name);
}
diff --git a/src/head.c b/src/head.c
@@ -4,9 +4,9 @@
#include <string.h>
int
-head(FILE* file, int lines)
+head(FILE *file, int lines)
{
- if (file == NULL) {
+ if(file == NULL) {
fprintf(
stderr, "error opening file: %i = %s\n", errno, strerror(errno));
return 1;
@@ -14,22 +14,22 @@ head(FILE* file, int lines)
int a;
int c = 0;
- while ((a = fgetc(file)) != EOF) {
- if (a == '\n')
+ while((a = fgetc(file)) != EOF) {
+ if(a == '\n')
++c;
putchar(a);
- if (c == lines)
+ if(c == lines)
return lines;
}
return lines;
}
int
-main(int argc, char* argv[])
+main(int argc, char *argv[])
{
int lines = 10;
- switch (argc) {
+ switch(argc) {
case 1:
head(stdin, lines);
break;
diff --git a/src/id.c b/src/id.c
@@ -3,11 +3,11 @@
#include <stdio.h>
#include <unistd.h>
int
-main(int argc, char* argv[])
+main(int argc, char *argv[])
{
int c = getopt(argc, argv, "Ggnru");
- struct passwd* user_data = getpwnam(getlogin());
- switch (c) {
+ struct passwd *user_data = getpwnam(getlogin());
+ switch(c) {
case 'g':
case 'u':
printf("%u\n", user_data->pw_gid);
diff --git a/src/kill.c b/src/kill.c
@@ -32,20 +32,20 @@ list_signals(void)
}
int
-main(int argc, char* argv[])
+main(int argc, char *argv[])
{
int sig = 0;
pid_t pid;
- if (argc == 1) {
+ if(argc == 1) {
fprintf(stderr, "expected something\n");
return 1;
}
- if (argv[1][1] == 'l') {
+ if(argv[1][1] == 'l') {
list_signals();
return 0;
}
- switch (argc) {
+ switch(argc) {
case 2:
sig = 15;
pid = atoi(argv[1]);
diff --git a/src/ln.c b/src/ln.c
@@ -4,25 +4,25 @@
#include <unistd.h>
int
-main(int argc, char* argv[])
+main(int argc, char *argv[])
{
- if (argc == 1) {
+ if(argc == 1) {
printf("Usage: ln oldfile newfile\n");
return 1;
}
int opts, fd, fflag;
- while ((opts = getopt(argc, argv, "sf")) != -1) {
- if (opts == 'f')
+ while((opts = getopt(argc, argv, "sf")) != -1) {
+ if(opts == 'f')
fflag = 1;
- switch (opts) {
+ switch(opts) {
case 's':
- if (fflag == 1 && (access(argv[3], F_OK) != 1)) {
- if (remove(argv[3]) == -1)
+ if(fflag == 1 && (access(argv[3], F_OK) != 1)) {
+ if(remove(argv[3]) == -1)
rmdir(argv[3]);
}
int symstat = symlink(argv[2], argv[3]);
- if (symstat == -1) {
+ if(symstat == -1) {
fprintf(stderr,
"Symlink error: %i = %s",
errno,
@@ -35,7 +35,7 @@ main(int argc, char* argv[])
break;
default:
fd = link(argv[1], argv[2]);
- if (fd == -1) {
+ if(fd == -1) {
fprintf(stderr,
"Error creating link: %i = %s\n",
errno,
diff --git a/src/ls.c b/src/ls.c
@@ -5,20 +5,20 @@
#include <string.h>
int
-recursive_list_dirs(const char* directory)
+recursive_list_dirs(const char *directory)
{
- DIR* dir = opendir(directory);
- if (dir == NULL) {
+ DIR *dir = opendir(directory);
+ if(dir == NULL) {
fprintf(stderr, "Error opening directory: %s\n", strerror(errno));
puts(directory);
return -1;
}
- struct dirent* ent;
+ struct dirent *ent;
- while ((ent = readdir(dir)) != NULL) {
- if (ent->d_type == DT_DIR) {
+ while((ent = readdir(dir)) != NULL) {
+ if(ent->d_type == DT_DIR) {
char path[1024];
- if (!strcmp(ent->d_name, ".") || !strcmp(ent->d_name, ".."))
+ if(!strcmp(ent->d_name, ".") || !strcmp(ent->d_name, ".."))
continue;
snprintf(path, sizeof(path), "%s/%s", directory, ent->d_name);
printf("%s/%s\n", path, ent->d_name);
@@ -32,14 +32,14 @@ recursive_list_dirs(const char* directory)
}
int
-main(int argc, char* argv[])
+main(int argc, char *argv[])
{
int c;
int all, show_slash, show_line, recursive;
all = show_slash = show_line = recursive = 0;
- while ((c = getopt(argc, argv, "lapR")) != -1) {
- switch (c) {
+ while((c = getopt(argc, argv, "lapR")) != -1) {
+ switch(c) {
case 'a':
all = 1;
break;
@@ -55,23 +55,23 @@ main(int argc, char* argv[])
}
}
char directory[256];
- if (!argv[optind])
+ if(!argv[optind])
strcpy(directory, "./");
else
strcpy(directory, argv[optind]); /* Very dirty code, i'll fix it
* later */
- DIR* dir = opendir(directory);
- struct dirent* ent;
- if (recursive) {
+ DIR *dir = opendir(directory);
+ struct dirent *ent;
+ if(recursive) {
recursive_list_dirs(directory);
return 0;
}
- if (dir != NULL) {
- while ((ent = readdir(dir)) != NULL) {
- if (ent->d_name[0] == '.' && !all)
+ if(dir != NULL) {
+ while((ent = readdir(dir)) != NULL) {
+ if(ent->d_name[0] == '.' && !all)
continue;
- if (!show_line) {
- if (ent->d_type == DT_DIR && show_slash)
+ if(!show_line) {
+ if(ent->d_type == DT_DIR && show_slash)
printf("%s/ ", ent->d_name);
else
printf("%s ", ent->d_name);
diff --git a/src/mkdir.c b/src/mkdir.c
@@ -4,10 +4,10 @@
#include <sys/stat.h>
int
-main(int argc, char* argv[])
+main(int argc, char *argv[])
{
int c = getopt(argc, argv, "p");
- if (argc == 1) {
+ if(argc == 1) {
fprintf(stderr, "specify path(s) to make\n");
return 1;
}
@@ -30,10 +30,10 @@ main(int argc, char* argv[])
return 0;
}
*/
- for (int i = 1; i < argc; i++) {
+ for(int i = 1; i < argc; i++) {
int fd = mkdir(argv[i], 420);
- if (fd == -1) {
+ if(fd == -1) {
fprintf(stderr, "Error creating dir %s\n", argv[i]);
return 1;
}
diff --git a/src/mv.c b/src/mv.c
@@ -28,9 +28,9 @@ move(const char *src, const char *dst)
}
*/
int
-main(int argc, char* argv[])
+main(int argc, char *argv[])
{
- if (argc == 1) {
+ if(argc == 1) {
fprintf(stderr, "usage: mv source destination\n");
return 1;
} else
diff --git a/src/rm.c b/src/rm.c
@@ -2,16 +2,16 @@
#include <stdio.h>
#include <string.h>
int
-main(int argc, char* argv[])
+main(int argc, char *argv[])
{
- if (argc == 1) {
+ if(argc == 1) {
printf("Specify files to remove.\n");
return 1;
}
- for (int i = 1; i < argc; i++) {
+ for(int i = 1; i < argc; i++) {
int fd = remove(argv[i]);
- if (fd == -1) {
+ if(fd == -1) {
fprintf(stderr,
"Error removing file: %i = %s",
errno,
diff --git a/src/rmdir.c b/src/rmdir.c
@@ -4,11 +4,11 @@
#include <unistd.h>
int
-main(int argc, char* argv[])
+main(int argc, char *argv[])
{
- for (int i = 1; i < argc; i++) {
- if (rmdir(argv[i])) {
+ for(int i = 1; i < argc; i++) {
+ if(rmdir(argv[i])) {
fprintf(stderr,
"rmdir: failed to remove '%s', %s\n",
argv[i],
diff --git a/src/shred.c b/src/shred.c
@@ -8,31 +8,31 @@
#include <unistd.h>
int
-fill_with_zeroes(const char* filename)
+fill_with_zeroes(const char *filename)
{
int fd = open(filename, O_WRONLY);
- if (fd == -1) {
+ if(fd == -1) {
printf("Error reading file: %i = %s\n", errno, strerror(errno));
return 1;
}
struct stat stat_struct; /* What name should i use? */
stat(filename, &stat_struct);
long int bytes_to_write = stat_struct.st_size;
- char* buf = NULL;
+ char *buf = NULL;
buf = malloc(bytes_to_write);
- for (int i = 0; i < bytes_to_write; i++)
+ for(int i = 0; i < bytes_to_write; i++)
write(fd, "\0\0\0\0\0", bytes_to_write + 2048);
free(buf);
return 0;
}
int
-main(int argc, char* argv[])
+main(int argc, char *argv[])
{
int c = getopt(argc, argv, "u"); /* TODO: add -f */
fill_with_zeroes(argv[1]);
- if (c == 'u')
+ if(c == 'u')
remove(argv[1]);
}
diff --git a/src/sleep.c b/src/sleep.c
@@ -3,9 +3,9 @@
#include <unistd.h>
int
-main(int argc, char* argv[])
+main(int argc, char *argv[])
{
- if (argc == 1) {
+ if(argc == 1) {
fprintf(stderr, "missing opperand\n");
return 1;
}
diff --git a/src/stat.c b/src/stat.c
@@ -5,16 +5,16 @@
#include <time.h>
int
-main(int argc, char** argv)
+main(int argc, char **argv)
{
- if (argc == 1) {
+ if(argc == 1) {
fprintf(stderr, "usage: stat FILE...\n");
return 1;
}
char mod_date[64], acc_date[64], creat_date[64];
struct stat file_data;
- for (int i = 1; i < argc; i++) {
- if (stat(argv[i], &file_data) == -1) {
+ for(int i = 1; i < argc; i++) {
+ if(stat(argv[i], &file_data) == -1) {
printf("Cannot stat '%s': %s\n", argv[i], strerror(errno));
continue;
}
@@ -37,7 +37,7 @@ main(int argc, char** argv)
file_data.st_uid,
file_data.st_gid);
/* Access, creation and modification date */
- struct tm* timeinfo;
+ struct tm *timeinfo;
/* Modification time */
timeinfo = localtime(&file_data.st_mtim.tv_sec);
strftime(mod_date, 64, "%F %H:%M:%S", timeinfo);
diff --git a/src/tee.c b/src/tee.c
@@ -8,22 +8,22 @@
int
tee(int fd)
{
- if (fd == -1) {
+ if(fd == -1) {
fprintf(stderr, "%s\n", strerror(errno));
return 1;
}
char buf[8192];
int read_bytes = 0;
- while ((read_bytes = read(0, buf, 8192)) > 0) {
+ while((read_bytes = read(0, buf, 8192)) > 0) {
write(fd, buf, read_bytes);
- if (fd != 1)
+ if(fd != 1)
write(1, buf, read_bytes);
}
return 0;
}
int
-main(int argc, char* argv[])
+main(int argc, char *argv[])
{
int c;
int append = 0;
@@ -32,8 +32,8 @@ main(int argc, char* argv[])
int FLAGS = O_WRONLY | O_CREAT; /* yeah, it will overwrite the thing if it
* can't read what's in the file, thanks
* POSIX! */
- while ((c = getopt(argc, argv, "ai")) != -1) {
- switch (c) {
+ while((c = getopt(argc, argv, "ai")) != -1) {
+ switch(c) {
case 'a':
append = 1;
break;
@@ -42,20 +42,20 @@ main(int argc, char* argv[])
break;
}
}
- if (argc == optind) {
- if (ignore_signt)
+ if(argc == optind) {
+ if(ignore_signt)
signal(SIGINT, SIG_IGN);
tee(1);
} else {
- if (argv[argc - 1][0] == '-')
+ if(argv[argc - 1][0] == '-')
fd = 1;
- if (append)
+ if(append)
FLAGS = O_RDWR | O_APPEND; /* Remember what I said? */
fd = open(argv[argc - 1], FLAGS);
- if (ignore_signt)
+ if(ignore_signt)
signal(SIGINT, SIG_IGN);
- if (tee(fd) == 1)
+ if(tee(fd) == 1)
return -1;
}
return 0;
diff --git a/src/test.c b/src/test.c
@@ -0,0 +1,11 @@
+#include <stdio.h>
+
+int
+main(void)
+{
+ int x = 3;
+ if(x == 3) {
+ puts("si");
+ }
+ return x;
+}
diff --git a/src/touch.c b/src/touch.c
@@ -6,16 +6,16 @@
#include <unistd.h>
int
-main(int argc, char* argv[])
+main(int argc, char *argv[])
{
- if (argc <= 1) {
+ if(argc <= 1) {
fprintf(stderr, "Give a file\n");
return 1;
}
int fd = creat(argv[1], 0644);
- if (fd == -1) {
+ if(fd == -1) {
fprintf(stderr,
"Error creating file: %i = %s\n",
errno,
diff --git a/src/uname.c b/src/uname.c
@@ -3,7 +3,7 @@
#include <string.h>
#include <sys/utsname.h>
-const char*
+const char *
get_operating_system()
{
#ifdef __gnu_linux__
@@ -22,7 +22,7 @@ get_operating_system()
}
int
-main(int argc, char* argv[])
+main(int argc, char *argv[])
{
int c;
int all = 0;
@@ -34,10 +34,10 @@ main(int argc, char* argv[])
int nothing = 0;
struct utsname kernel_info;
- if (argc == 1)
+ if(argc == 1)
nothing = 1;
- while ((c = getopt(argc, argv, "amnrsv")) != -1) {
- switch (c) {
+ while((c = getopt(argc, argv, "amnrsv")) != -1) {
+ switch(c) {
case 'a':
all = 1;
break;
@@ -61,7 +61,7 @@ main(int argc, char* argv[])
uname(&kernel_info);
- if (all) {
+ if(all) {
printf("%s %s %s %s %s %s\n",
kernel_info.sysname,
kernel_info.nodename,
@@ -70,15 +70,15 @@ main(int argc, char* argv[])
kernel_info.machine,
get_operating_system());
} else {
- if (machine)
+ if(machine)
printf("%s ", kernel_info.machine);
- if (node_name)
+ if(node_name)
printf("%s ", kernel_info.nodename);
- if (kernel_release)
+ if(kernel_release)
printf("%s ", kernel_info.release);
- if (kernel_name || nothing)
+ if(kernel_name || nothing)
printf("%s ", kernel_info.sysname);
- if (operating_system)
+ if(operating_system)
printf("%s", get_operating_system());
printf("\n");
}
diff --git a/src/unlink.c b/src/unlink.c
@@ -4,15 +4,15 @@
#include <unistd.h>
int
-main(int argc, char* argv[])
+main(int argc, char *argv[])
{
- if (argc == 1) {
+ if(argc == 1) {
fprintf(stderr, "What do I unlink?\n");
return 1;
}
int fd = unlink(argv[1]);
- if (fd == -1) {
+ if(fd == -1) {
fprintf(stderr, "Error unlinking: %i = %s\n", errno, strerror(errno));
}
return 0;
diff --git a/src/wc.c b/src/wc.c
@@ -19,10 +19,10 @@ struct wc_values
};
int
-wc(const char* filename, struct wc_values* data)
+wc(const char *filename, struct wc_values *data)
{
- FILE* file = fopen(filename, "r");
- if (file == NULL) {
+ FILE *file = fopen(filename, "r");
+ if(file == NULL) {
fprintf(stderr,
"error opening file %s: %s\n",
filename,
@@ -33,13 +33,13 @@ wc(const char* filename, struct wc_values* data)
char buf;
int newlines, spaces, bytes = 0;
newlines = spaces = bytes = 0;
- while ((c = fread(&buf, 1, 1, file)) > 0) {
- if (!isascii(buf))
+ while((c = fread(&buf, 1, 1, file)) > 0) {
+ if(!isascii(buf))
buf = toascii(buf);
bytes++;
- if (buf == '\n')
+ if(buf == '\n')
newlines++;
- if (isspace(buf))
+ if(isspace(buf))
spaces++;
}
data->bytes = bytes;
@@ -55,23 +55,23 @@ wc(const char* filename, struct wc_values* data)
}
void
-print_values(const char* filename, struct wc_values data)
+print_values(const char *filename, struct wc_values data)
{
- if (show_bytes && show_lines && show_words)
+ if(show_bytes && show_lines && show_words)
printf("%i %i %i", data.lines, data.words, data.bytes);
else {
- if (!show_lines)
+ if(!show_lines)
printf("%i ", data.lines);
- if (!show_words)
+ if(!show_words)
printf("%i ", data.words);
- if (!show_bytes)
+ if(!show_bytes)
printf("%i ", data.bytes);
}
printf(" %s\n", filename);
}
int
-main(int argc, char* argv[])
+main(int argc, char *argv[])
{
int c;
struct wc_values data;
@@ -79,8 +79,8 @@ main(int argc, char* argv[])
int return_value = 0; /* Please let me know a better name */
show_lines = show_words = show_bytes = 1;
/* Process arguments */
- while ((c = getopt(argc, argv, "lwcm")) > 0) {
- switch (c) {
+ while((c = getopt(argc, argv, "lwcm")) > 0) {
+ switch(c) {
case 'l':
show_lines = 0;
break;
@@ -93,19 +93,19 @@ main(int argc, char* argv[])
break;
}
}
- if (optind == argc) {
+ if(optind == argc) {
wc("/dev/stdin", &data); /* lol */
print_values("stdin", data);
} else
- for (int i = optind; i < argc; i++) {
- if (argv[i][0] == '-' && argv[i][1] == '\0')
+ for(int i = optind; i < argc; i++) {
+ if(argv[i][0] == '-' && argv[i][1] == '\0')
return_value = wc("/dev/stdin", &data);
else
return_value = wc(argv[i], &data);
- if (return_value == 0)
+ if(return_value == 0)
print_values(argv[i], data);
}
- if (argc > optind + 1)
+ if(argc > optind + 1)
printf("%i %i %i total\n",
data.total_lines,
data.total_words,
diff --git a/src/whoami.c b/src/whoami.c
@@ -5,6 +5,6 @@
int
main(void)
{
- struct passwd* user_data = getpwuid(getuid());
+ struct passwd *user_data = getpwuid(getuid());
printf("%s\n", user_data->pw_name);
}
diff --git a/src/yes.c b/src/yes.c
@@ -1,13 +1,13 @@
#include <stdio.h>
int
-main(int argc, char* argv[])
+main(int argc, char *argv[])
{
- if (argc > 1)
- while (1)
+ if(argc > 1)
+ while(1)
puts(argv[1]);
else
- while (1)
+ while(1)
puts("y");
return 0;
}