/*-------------------------------------------------------------------*/ /* testlowlevelout.c */ /* The creat, write, and close system calls. */ /*-------------------------------------------------------------------*/ #include #include #include int main(int argc, char *argv[]) { int iFd; int iRet; int iBytesWritten; char pcBuffer[] = "somedata\n"; /* Write "somedata\n" to a file named tempfile. */ iFd = creat("tempfile", 0600); if (iFd == -1) {perror(argv[0]); return 1; } iBytesWritten = 0; while (iBytesWritten < 9) { iRet = write(iFd, pcBuffer + iBytesWritten, 9 - iBytesWritten); if (iRet == -1) {perror(argv[0]); return 1; } iBytesWritten += iRet; } iRet = close(iFd); if (iRet == -1) {perror(argv[0]); return 1; } return 0; } /* Sample execution: $ gcc -Wall -ansi -pedantic -o testlowlevelout testlowlevelout.c $ testlowlevelout $ cat tempfile somedata $ */