This commit is contained in:
Your Name 2023-11-14 23:13:31 +03:00
parent 2e79541d3b
commit 8ee0a82786
10 changed files with 32 additions and 12 deletions

View File

@ -10,6 +10,6 @@ const char *objects[] = {
/* "sysutils" */
};
#define CFLAGS "-Wall", "-Werror", "-Wextra", "-pedantic", "-flto", "-Os", "-s", "-I", "../libmu"
#define CFLAGS "-Wall", "-Werror", "-Wextra", "-pedantic", "-flto", "-Os", "-s", "-I", "../libmu", "-I", "../"
#define CC "cc"
#endif

14
config.h Normal file
View File

@ -0,0 +1,14 @@
#ifndef _CONFIG_H
#define _CONFIG_H
/* Depends: cat tee wc */
#define BUF_SIZE 4096
/* Random source for shred */
#define RAND_SOURCE "/dev/urandom"
/* Options. To disable, comment line */
/* Add escape-char support in echo */
#define ECHO_FANCY
#endif

View File

@ -3,9 +3,10 @@
#include <errno.h>
#include <string.h>
#include <unistd.h>
#include "config.h"
void cat(const int fd) {
char buf[4096];
char buf[BUF_SIZE + 1];
ssize_t len;
while ((len = read(fd, buf, sizeof(buf))) > 0)

View File

@ -2,7 +2,6 @@
#include <libgen.h>
int main(const int argc, char **argv) {
if (argc <= 1) {
printf("dirname [dirname]\n");
return 1;

View File

@ -1,8 +1,10 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "config.h"
void format(char *str) {
#ifdef ECHO_FANCY
for (size_t i = 0; i < strlen(str); i++) {
unsigned int c = str[i];
if (c == '\\') {
@ -51,6 +53,11 @@ void format(char *str) {
putchar(c);
}
#else
fputs(str, stdout);
#endif
}
int main(int argc, char **argv) {

View File

@ -20,7 +20,6 @@ int ln(const char *src, const char *dst) {
}
int main(int argc, char **argv) {
int opt;
while ((opt = getopt(argc, argv, "sf")) != -1) {
switch (opt) {

View File

@ -6,8 +6,7 @@
#include <string.h>
#include <sys/mman.h>
#include <sys/stat.h>
#define RAND_SOURCE "/dev/urandom"
#include "config.h"
unsigned int f_flag;
unsigned int u_flag;

View File

@ -3,6 +3,7 @@
#include <errno.h>
#include <unistd.h>
#include <stdlib.h>
#include "config.h"
int main(int argc, char **argv) {
int flag = O_TRUNC;
@ -38,11 +39,11 @@ int main(int argc, char **argv) {
}
char in[4096];
char buf[BUF_SIZE + 1];
off_t bytes = 0;
while ((bytes = read(STDIN_FILENO, in, sizeof(in)))) {
write(STDOUT_FILENO, in, bytes);
write(fd, in, bytes);
while ((bytes = read(STDIN_FILENO, buf, sizeof(buf)))) {
write(STDOUT_FILENO, buf, bytes);
write(fd, buf, bytes);
}
close(fd);

View File

@ -4,6 +4,7 @@
#include <ctype.h>
#include <unistd.h>
#include <string.h>
#include "config.h"
/* cmd arguments l - lines c - bytes w - words */
unsigned int l_flag;
@ -20,7 +21,7 @@ unsigned int tbytes;
unsigned int tlines;
void count(const int fd) {
char buf[4096];
char buf[BUF_SIZE + 1];
off_t n = 0;
int in_word = 1;

View File

@ -1,7 +1,6 @@
#include <sys/types.h>
#include <unistd.h>
#include <pwd.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>