This commit is contained in:
Your Name 2024-07-09 11:02:46 +03:00
parent 7a048f8787
commit f8dd7660ae
143 changed files with 74 additions and 248 deletions

View file

@ -5,7 +5,7 @@
#include <stdlib.h>
char s_flag;
int compare(FILE *fp1, FILE *fp2) {
int compare(FILE *fp1, FILE *fp2, const char *s1, const char *s2) {
if (fp1 == fp2)
return 0;
@ -18,7 +18,17 @@ int compare(FILE *fp1, FILE *fp2) {
ch1 = getc(fp1);
ch2 = getc(fp2);
if (ch1 != ch2) {
if (ch1 == EOF) {
printf("EOF on %s\n", s1);
return 1;
}
else if (ch2 == EOF) {
printf("EOF on %s\n", s2);
return 1;
}
else if (ch1 != ch2) {
if (!s_flag)
printf("files differ at byte %zu and line %zu\n", byte, lines);
@ -52,7 +62,7 @@ FILE *file_open(const char *path) {
FILE *fp = fopen(path, "r");
if (fp == NULL) {
fprintf(stderr, "cmp: %s\n", strerror(errno));
exit(1);
return NULL;
}
return fp;
@ -82,6 +92,9 @@ int main(int argc, char **argv) {
FILE *fp1 = NULL;
FILE *fp2 = stdin;
char *s1 = "-";
char *s2 = "-";
switch (argc) {
case 4:
skip2 = parse_int(argv[3]);
@ -92,11 +105,21 @@ int main(int argc, char **argv) {
/* fallthrough */
case 2:
s2 = argv[1];
fp2 = file_open(argv[1]);
if (fp2 == NULL)
exit(1);
/* fallthrough */
case 1:
s1 = argv[0];
fp1 = file_open(argv[0]);
if (fp1 == NULL) {
fclose(fp2);
exit(1);
}
break;
default:
@ -118,7 +141,7 @@ int main(int argc, char **argv) {
return 1;
}
int ret = compare(fp1, fp2);
int ret = compare(fp1, fp2, s1, s2);
fclose(fp1);
fclose(fp2);

View file

@ -1,3 +0,0 @@
#!/bin/sh
project_dir=$(pwd)
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC

View file

@ -1,3 +0,0 @@
#!/bin/sh
project_dir=$(pwd)
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC

View file

@ -1,3 +0,0 @@
#!/bin/sh
project_dir=$(pwd)
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC

View file

@ -1,3 +0,0 @@
#!/bin/sh
project_dir=$(pwd)
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC

View file

@ -1,3 +0,0 @@
#!/bin/sh
project_dir=$(pwd)
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC

View file

@ -1,3 +0,0 @@
#!/bin/sh
project_dir=$(pwd)
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC

View file

@ -1,3 +0,0 @@
#!/bin/sh
project_dir=$(pwd)
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC

View file

@ -1,3 +0,0 @@
#!/bin/sh
project_dir=$(pwd)
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC

View file

@ -1,3 +0,0 @@
#!/bin/sh
project_dir=$(pwd)
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC

View file

@ -1,3 +0,0 @@
#!/bin/sh
project_dir=$(pwd)
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC

View file

@ -1,3 +0,0 @@
#!/bin/sh
project_dir=$(pwd)
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC

View file

@ -1,3 +0,0 @@
#!/bin/sh
project_dir=$(pwd)
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC

View file

@ -1,3 +0,0 @@
#!/bin/sh
project_dir=$(pwd)
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC

View file

@ -1,3 +0,0 @@
#!/bin/sh
project_dir=$(pwd)
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC

View file

@ -1,3 +0,0 @@
#!/bin/sh
project_dir=$(pwd)
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC

View file

@ -1,3 +0,0 @@
#!/bin/sh
project_dir=$(pwd)
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC

View file

@ -1,3 +0,0 @@
#!/bin/sh
project_dir=$(pwd)
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC

View file

@ -1,3 +0,0 @@
#!/bin/sh
project_dir=$(pwd)
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC

View file

@ -1,3 +0,0 @@
#!/bin/sh
project_dir=$(pwd)
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC

View file

@ -1,3 +0,0 @@
#!/bin/sh
project_dir=$(pwd)
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC

View file

@ -1,3 +0,0 @@
#!/bin/sh
project_dir=$(pwd)
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC

View file

@ -1,3 +0,0 @@
#!/bin/sh
project_dir=$(pwd)
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC

View file

@ -1,3 +0,0 @@
#!/bin/sh
project_dir=$(pwd)
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC

View file

@ -1,3 +0,0 @@
#!/bin/sh
project_dir=$(pwd)
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC

View file

@ -1,3 +0,0 @@
#!/bin/sh
project_dir=$(pwd)
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC

View file

@ -1,3 +0,0 @@
#!/bin/sh
project_dir=$(pwd)
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC

View file

@ -1,3 +0,0 @@
#!/bin/sh
project_dir=$(pwd)
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC

View file

@ -1,3 +0,0 @@
#!/bin/sh
project_dir=$(pwd)
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC

View file

@ -1,3 +0,0 @@
#!/bin/sh
project_dir=$(pwd)
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC

View file

@ -1,3 +0,0 @@
#!/bin/sh
project_dir=$(pwd)
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC

View file

@ -1,3 +0,0 @@
#!/bin/sh
project_dir=$(pwd)
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC

View file

@ -1,3 +0,0 @@
#!/bin/sh
project_dir=$(pwd)
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC

View file

@ -1,3 +0,0 @@
#!/bin/sh
project_dir=$(pwd)
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC

View file

@ -1,3 +0,0 @@
#!/bin/sh
project_dir=$(pwd)
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC

View file

@ -1,3 +0,0 @@
#!/bin/sh
project_dir=$(pwd)
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC

View file

@ -1,3 +0,0 @@
#!/bin/sh
project_dir=$(pwd)
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC

View file

@ -1,3 +0,0 @@
#!/bin/sh
project_dir=$(pwd)
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC

View file

@ -1,3 +0,0 @@
#!/bin/sh
project_dir=$(pwd)
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC

View file

@ -1,3 +0,0 @@
#!/bin/sh
project_dir=$(pwd)
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC

View file

@ -1,3 +0,0 @@
#!/bin/sh
project_dir=$(pwd)
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC

View file

@ -1,3 +0,0 @@
#!/bin/sh
project_dir=$(pwd)
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC

View file

@ -1,3 +0,0 @@
#!/bin/sh
project_dir=$(pwd)
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC

View file

@ -1,3 +0,0 @@
#!/bin/sh
project_dir=$(pwd)
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC

View file

@ -1,3 +0,0 @@
#!/bin/sh
project_dir=$(pwd)
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC

View file

@ -1,3 +0,0 @@
#!/bin/sh
project_dir=$(pwd)
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC

View file

@ -1,3 +0,0 @@
#!/bin/sh
project_dir=$(pwd)
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC

View file

@ -1,3 +0,0 @@
#!/bin/sh
project_dir=$(pwd)
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC

View file

@ -1,3 +0,0 @@
#!/bin/sh
project_dir=$(pwd)
echo *.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC

View file

@ -1,3 +0,0 @@
#!/bin/sh
project_dir=$(pwd)
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC

View file

@ -1,3 +0,0 @@
#!/bin/sh
project_dir=$(pwd)
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC

View file

@ -1,5 +0,0 @@
#!/bin/sh
project_dir=$(pwd)
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC
cp reboot $OUTPUT/reboot
cp poweroff $OUTPUT/poweroff

View file

@ -1,2 +0,0 @@
#!/bin/sh
kill -s USR1 1

View file

@ -1,2 +0,0 @@
#!/bin/sh
kill -s USR2 1

View file

@ -5,6 +5,7 @@
#include <signal.h>
#include <dirent.h>
#include <unistd.h>
#include "proc_parser.h"
typedef struct {
const char *name;
@ -58,11 +59,12 @@ int my_kill(pid_t pid, int signal) {
}
int main(int argc, char **argv) {
unsigned int a_flag = 0;
char a_flag = 0;
char n_flag = 0;
int signal = SIGTERM;
int opt;
while ((opt = getopt(argc, argv, "s:la")) != -1) {
while ((opt = getopt(argc, argv, "s:lan")) != -1) {
switch (opt) {
case 'l':
for (size_t i = 0; i < sizeof(signals) / sizeof(signals[0]); i++)
@ -78,8 +80,12 @@ int main(int argc, char **argv) {
a_flag = 1;
break;
case 'n':
n_flag = 1;
break;
default:
printf("kill [lsa] [pid1 pid2...]\n\t-s SIG\n\t-l List all signals\n\t-a Kill all process\n");
printf("kill [lsan] [pid1 pid2/str1...]\n\t-s SIG\n\t-l List all signals\n\t-a Kill all process\n\t-n STR kill processes by name\n");
return 0;
}
}
@ -87,9 +93,14 @@ int main(int argc, char **argv) {
argv += optind;
argc -= optind;
if ((n_flag || !a_flag) && argc == 0) {
fprintf(stderr, "kill: missing operands\n");
return 1;
}
int ret = 0;
if (a_flag) {
if (a_flag || n_flag) {
DIR *dp = opendir("/proc");
if (dp == NULL) {
fprintf(stderr, "kill: /proc: %s\n", strerror(errno));
@ -100,24 +111,38 @@ int main(int argc, char **argv) {
struct dirent *ep;
while ((ep = readdir(dp)) != NULL) {
pid_t pid = atoi(ep->d_name);
if (pid == 0 || pid == my_pid)
pid_t pid = strtoul(ep->d_name, 0L, 10);
if (pid == 0)
continue;
if (my_kill(pid, signal))
ret = 1;
if (n_flag) {
struct mu_proc proc;
if (mu_proc_parser("kill", pid, &proc))
ret = 1;
for (int i = 0; i < argc; i++) {
if (!strcmp(proc.prog, argv[i]))
if (my_kill(pid, signal))
ret = 1;
}
}
else if (a_flag) {
if (pid == my_pid)
continue;
if (my_kill(pid, signal))
ret = 1;
}
}
closedir(dp);
}
else {
for (int i = 0; i < argc; i++) {
pid_t pid = atoi(argv[i]);
if (my_kill(pid, signal))
for (int i = 0; i < argc; i++)
if (my_kill(strtoul(argv[i], 0L, 10), signal))
ret = 1;
}
}
return ret;

View file

@ -1,3 +0,0 @@
#!/bin/sh
project_dir=$(pwd)
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC -lcrypt

View file

@ -1,3 +0,0 @@
#!/bin/sh
project_dir=$(pwd)
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC -lcrypt

View file

@ -1,3 +0,0 @@
#!/bin/sh
project_dir=$(pwd)
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC -lcrypt

View file

@ -1,3 +0,0 @@
#!/bin/sh
project_dir=$(pwd)
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) -lm | xargs $CC

View file

@ -1,3 +0,0 @@
#!/bin/sh
project_dir=$(pwd)
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC

View file

@ -1,3 +0,0 @@
#!/bin/sh
project_dir=$(pwd)
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC

View file

@ -1,3 +0,0 @@
#!/bin/sh
project_dir=$(pwd)
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC

View file

@ -1,3 +0,0 @@
#!/bin/sh
project_dir=$(pwd)
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC

Some files were not shown because too many files have changed in this diff Show more