, K & R 1st Edition, 1978 , . .. .
Unix- . Unix , 14- , . , MacOS X (10.6.2) Solaris (10) Linux (SuSE Linux Enterprise Edition 10, 2.6.16.60-0.21-smp). :
read failed: (21: Is a directory)
POSIX , , , . , "fchdir()" , , , .
, opendir() , readdir() .. K & R raw open() read() ..
, , 30 , .
Windows POSIX , Cygwin MingW, opendir() readdir(), open() read() .
Or you can use the native Windows API that BillyONeal refers to, FindFirstFile and relatives.
Test code:
#include <unistd.h>
#include <stdio.h>
#include <string.h>
#include <fcntl.h>
#include <errno.h>
int main()
{
int fd = open(".", O_RDONLY);
if (fd != -1)
{
char buffer[256];
ssize_t n = read(fd, buffer, sizeof(buffer));
if (n < 0)
{
int errnum = errno;
printf("read failed: (%d: %s)\n", errnum, strerror(errnum));
}
else
printf("read OK: %d bytes (%s)\n", (int)n, buffer);
close(fd);
}
return(0);
}