Skip to content

Commit

Permalink
Writer implemented as in requirements
Browse files Browse the repository at this point in the history
  • Loading branch information
Dariusz authored and Dariusz committed Jan 9, 2025
1 parent 8bae9f4 commit 43d7fe7
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 3 deletions.
1 change: 1 addition & 0 deletions assignments/assignment2/fileresult.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
writer: ELF 64-bit LSB executable, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-aarch64.so.1, for GNU/Linux 3.7.0, with debug_info, not stripped
6 changes: 3 additions & 3 deletions finder-app/finder-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ then
fi
fi
#echo "Removing the old writer utility and compiling as a native application"
#make clean
#make
make clean
make

for i in $( seq 1 $NUMFILES)
do
./writer.sh "$WRITEDIR/${username}$i.txt" "$WRITESTR"
./writer "$WRITEDIR/${username}$i.txt" "$WRITESTR"
done

OUTPUTSTRING=$(./finder.sh "$WRITEDIR" "$WRITESTR")
Expand Down
11 changes: 11 additions & 0 deletions finder-app/makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
CC = gcc
CFLAGS = -g
RM = rm -f

default: writer

writer: writer.c
$(CROSS_COMPILE)$(CC) $(CFLAGS) -o writer writer.c

clean veryclean:
$(RM) writer
56 changes: 56 additions & 0 deletions finder-app/writer.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#include <stdio.h>
#include <syslog.h>


int main(int argc, char **argv)
{
char* str_content;
char* f_name;
FILE *fp = NULL;

openlog(NULL, 0, LOG_USER);

if (argc < 2)
{
syslog(LOG_ERR, "Wrong number of arguments %d", argc );
return 1;
}
else
{
str_content = argv[2];
f_name = argv[1];

if((str_content == NULL) || (f_name == NULL))
{
syslog(LOG_ERR, "Wrong argument");
return 1;
}
else
{
syslog(LOG_DEBUG, "Writing %s to %s", str_content, f_name );

fp = fopen(f_name ,"w");

if ( fp != NULL)
{
if (0 > fprintf(fp, "%s", str_content))
{
syslog(LOG_DEBUG, "Writing to file failed" );
return 1;
}
fclose(fp);
return 0;
}
else
{
return 1;
}

}
}




printf("writer done\n");
}

0 comments on commit 43d7fe7

Please sign in to comment.