first commit

This commit is contained in:
corey 2024-02-23 12:47:39 -06:00
commit fc4a71d4a9
3 changed files with 40 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
*.o
/rot13

9
Makefile Normal file
View File

@ -0,0 +1,9 @@
CC= tcc
CFLAGS= -Wall -Wextra -Werror
LDFLAGS= -s
all: rot13
%: %.c
$(CC) $^ -o $@ $(CFLAGS) $(LDFLAGS)
clean:
$(RM) *.o rot13

29
rot13.c Normal file
View File

@ -0,0 +1,29 @@
#include<unistd.h>
#include<fcntl.h>
int main(int argc,char**argv)
{
int fd=0;
if(argc>1)
{
fd=open(argv[1],O_RDONLY);
if(fd<0)
{
write(2,"failed to open file\n",20);
fd=0;
}
}
int c;
while(read(fd,&c,1))
{
if(c>='a'&&c<='z')
c=((c-'a')+13)%26+'a';
else if(c>='A'&&c<='Z')
c=((c-'A')+13)%26+'A';
else if(c>='0'&&c<='9')
c=((c-'0')+10)%10+'0';
write(1,&c,1);
}
}