irst version on that git repo
This commit is contained in:
commit
46ccebf956
13 changed files with 844 additions and 0 deletions
45
cat.c
Normal file
45
cat.c
Normal file
|
@ -0,0 +1,45 @@
|
|||
#include"stdin.h"
|
||||
#include"utils.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include<sys/stat.h>
|
||||
#include<string.h>
|
||||
int main(int argc,char *argv[])
|
||||
{;
|
||||
if(argc==1) {
|
||||
read_from_stdin();
|
||||
return 0;
|
||||
}
|
||||
if(strcmp(argv[1],"-v")==0)
|
||||
{
|
||||
printf("patricus utils, version %s",version);
|
||||
return 0;
|
||||
}
|
||||
for(int meowing=1;meowing<argc;meowing++){
|
||||
if(strcmp(argv[meowing ],"-")==0)
|
||||
{
|
||||
read_from_stdin();
|
||||
}
|
||||
FILE *f=fopen(argv[meowing],"r");
|
||||
//opening a file from cli arguments
|
||||
struct stat filecheck;
|
||||
//here we see if the user is an idiot and the file doesn't exist, we won't crash if a file is dir so
|
||||
if(stat(argv[meowing],&filecheck)==-1) {
|
||||
printf("file not found.");
|
||||
return 1;
|
||||
}
|
||||
//I actually wrote a check for dirs.
|
||||
if((filecheck.st_mode&S_IFDIR)==S_IFDIR)
|
||||
{
|
||||
printf("it is a directory");
|
||||
}
|
||||
int size=ftell(f);
|
||||
char *meow=malloc(1);
|
||||
fseek(f,0,SEEK_SET);
|
||||
int readBytes;
|
||||
while ((readBytes = fread(meow, 1, 1, f ))== 1) {
|
||||
printf("%c",*meow);
|
||||
}
|
||||
fclose(f);
|
||||
free(meow);
|
||||
}}
|
Loading…
Add table
Add a link
Reference in a new issue