os-70-350

os-70-350 Commit Details


Date:2014-01-17 22:16:56 (11 years 7 months ago)
Author:Natalie Adams
Branch:master
Commit:ac0bd23e2c8a3eb0af50b361adbc8c562559e18c
Parents: 2e1e315e2939be19172ae2bb92843646ba9ffbe1
Message:Adding examples from class

Changes:

File differences

inclass-cp-example/linux.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <stdio.h>
#include <unistd.h>
#include <errno.h>
#include <fcntl.h>
// cp2 file1 file2
int main(int argc, char * args[])
{
int infile, outfile;
int numofbytesread;
char buffer[20];
infile = open(args[1], O_RDONLY, 0700);
if (infile == ENOENT)
{
printf("Could not find file!");
return 0;
}
outfile = open(args[2], O_WRONLY | O_CREAT, 0700);
while((numofbytesread = read(infile, buffer, 20)))
write(outfile, buffer, numofbytesread);
close(infile);
close(outfile);
return 0;
}
inclass-cp-example/windows.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include <stdio.h>
#include <Windows.h>
#define false 0
#define true 1
// cp2 file1 file2
int main(int argc, char * args[])
{
HANDLE infile;
HANDLE outfile;
DWORD numberofbytesread;
DWORD numberofbyteswritten;
char buffer[20];
infile = CreateFileA(args[1], GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (GetLastError() == ERROR_FILE_NOT_FOUND)
{
printf("Could not find file!");
return 0;
}
outfile = CreateFileA(args[2], GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
while(true)
{
ReadFile(infile, buffer, 20, &numberofbytesread, NULL);
if (numberofbytesread == 0)
break;
WriteFile(outfile, buffer, numberofbytesread, &numberofbyteswritten, NULL);
}
CloseHandle(infile);
CloseHandle(outfile);
return 0;
}

Archive Download the corresponding diff file

Branches

Number of commits:
Page rendered in 0.27648s using 14 queries.