1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
|
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
#include <sys/stat.h>
int main(int argc, char *argv[])
// Reads
{
char char_read;
int fd;
if (argc < 2)
{
fprintf(stderr, "readfile: Filename must be specified\n");
exit(EXIT_FAILURE);
}
if ((fd = open(argv[1], O_RDONLY)) < 0) {
perror(argv[1]);
exit(EXIT_FAILURE);
}
while(read(fd, &char_read, 1) > 0)
printf("%c", char_read);
exit(EXIT_SUCCESS);
}
// fgetc()
char char_read;
FILE *fileptr;
if (argc < 2)
{
fprintf(stderr, "readfile: Filename must be specified\n");
exit(EXIT_FAILURE);
}
if ((fileptr = fopen(argv[1], "r")) == NULL)
{
perror(argv[1]);
exit(EXIT_FAILURE);
}
while((char_read = fgetc(fileptr)) != EOF)
printf("%c", char_read);
exit(EXIT_SUCCESS);
}
char mode[] = "";
char buf[] = "";
int i;
i = strtol(mode, 0, 8);
if (chmod (buf,i) < 0)
{
fprint(stderr, "%s: error in chmod(%s, %s) - %d (%s)\n",
argv[0], buf, mode, errno, strerror(errno));
exit(1);
}
return(0);
}
|