Skip to content
Snippets Groups Projects
Commit d085ec91 authored by Max Schrötter's avatar Max Schrötter
Browse files

init

parents
No related branches found
No related tags found
No related merge requests found
CC = gcc
all: workdir.c print_file.c
${CC} -o workdir workdir.c
${CC} -o print_file print_file.c
clean:
rm -f workdir print_file
#include <stdlib.h>
#include <fcntl.h>
#include <sys/types.h>
#include <unistd.h>
#include <stdio.h>
#define SIZE 512
int main() {
int fd = open("./test.txt", O_RDWR);
if (fd == -1){
perror("could not open file");
return EXIT_FAILURE;
}
char * buffer = (char *) calloc(SIZE, sizeof(char));
ssize_t r = read(fd, buffer, SIZE-1);
if (r == -1) {
perror("could not read file");
free(buffer);
close(fd);
return EXIT_FAILURE;
}
printf("%.*s", SIZE-1, buffer);
free(buffer);
close(fd);
return EXIT_SUCCESS;
}
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
char *mywdfunc(unsigned int bufsize) {
if (bufsize < 100) {
return NULL;
}
char *buf = (char *)calloc(bufsize,sizeof(char));
if (buf) {
getcwd(buf,bufsize-1);
}
return buf;
}
int main() {
char *ret = mywdfunc(512);
printf("%s", ret);
free(ret);
return EXIT_SUCCESS;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment