Исправление korvin_, (текущая версия) :
В рамках пятницы...
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
typedef int (*FileProcedure)(int fd);
int
with_new_file(char* path, FileProcedure proc) {
int fd = open(path, O_CREAT | O_RDWR , 0664);
if (fd == -1) {
return -1;
}
int err = proc(fd);
close(fd);
return err;
}
int
do_nothing(int fd) {
return 0;
}
int
main(int argc, char** argv) {
for (int i = 1; i < argc; i++) {
int err = with_new_file(argv[i], do_nothing);
if (err != 0) {
return err;
}
}
return 0;
}
Исходная версия korvin_, :
В рамках пятницы...
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
typedef int (*FileProcedure)(int fd);
int
with_new_file(char* name, FileProcedure proc) {
int fd = open(name, O_CREAT | O_RDWR , 0664);
if (fd == -1) {
return -1;
}
int err = proc(fd);
close(fd);
return err;
}
int
do_nothing(int fd) {
return 0;
}
int
main(int argc, char** argv) {
for (int i = 1; i < argc; i++) {
int err = with_new_file(argv[i], do_nothing);
if (err != 0) {
return err;
}
}
return 0;
}