|
CS 456 - Systems Programming
Spring 2024
|
Displaying ./code/jan31/fd2.c
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#define arr 100
int main (int argc, char **argv){
if (argc < 2){
fprintf(stderr, "Usage %s file\n",argv[0]);
exit(1);
}
//open a file, print it's file descriptor, then exit)
int fi[arr]; // array for file descriptors
for (int i = 1; i < argc; i++){
int fd = open(argv[i], O_RDONLY);
fi[i] = fd;
}
for (int i = 1; i < argc; i++){
printf("fd of %s: %d\n", argv[i], fi[i]);
}
for (int i = 1; i < argc; i++){
close(fi[i]);
}
return 0;
}
|