Добавил:
Studfiles2
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз:
Предмет:
Файл:Тестовые примеры / ch7 / test_access
.C #include <sys/types.h>
#include <unistd.h>
#include <fcntl.h>
int main (int argc, char* argv[])
{
char buf[256];
int fdesc, len;
while ( --argc > 0)
{
if (access(*++argv,F_OK)) // a brand new file
{
fdesc = open(*argv,O_WRONLY|O_CREAT,0744);
write(fdesc,"Hello world\n",12);
} else // file exists, read data
{
fdesc = open(*argv,O_RDONLY);
while (len=read(fdesc,buf,256))
write(fdesc,buf,len);
}
close(fdesc);
} /* for each argument */
return 0;
}
#include <unistd.h>
#include <fcntl.h>
int main (int argc, char* argv[])
{
char buf[256];
int fdesc, len;
while ( --argc > 0)
{
if (access(*++argv,F_OK)) // a brand new file
{
fdesc = open(*argv,O_WRONLY|O_CREAT,0744);
write(fdesc,"Hello world\n",12);
} else // file exists, read data
{
fdesc = open(*argv,O_RDONLY);
while (len=read(fdesc,buf,256))
write(fdesc,buf,len);
}
close(fdesc);
} /* for each argument */
return 0;
}
Соседние файлы в папке ch7