00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include <stdio.h>
00015 #include <stdlib.h>
00016 #include <unistd.h>
00017 #include <errno.h>
00018 #include "../lib/testutils.h"
00019
00020 int
00021 main()
00022 {
00023 int f1, f2;
00024 int i = 42;
00025 int j = -999;
00026 int intbuf = 0;
00027 int rc = 0;
00028 int save_errno = 0;
00029
00030
00031
00032
00033
00034 f1 = open("FILE1", O_RDWR | O_CREAT | O_TRUNC);
00035 TEST_POSITIVE(f1, "Unable to open FILE1");
00036
00037
00038 f2 = open("FILE2", O_RDWR | O_CREAT | O_TRUNC);
00039 TEST_POSITIVE(f2, "Unable to open FILE2");
00040
00041 TEST_NOT_EQUAL(f1, f2, "fd f1 == f2");
00042
00043
00044 rc = write(f1, (char *) &i, sizeof(i));
00045 TEST_EQUAL(rc, sizeof(i), "write to f1 does not write/return proper value");
00046
00047
00048 rc = write(f2, (char *) &j, sizeof(j));
00049 TEST_EQUAL(rc, sizeof(j), "write to f2 does not write/return proper value");
00050
00051 rc = close(f1);
00052 TEST_EQUAL(rc, SUCCESS, "close f1 failed");
00053
00054 rc = close(f1);
00055 save_errno = errno;
00056
00057 TEST_NEGATIVE(rc, "close f1 second time didn't fail");
00058
00059 rc = close(f2);
00060 TEST_EQUAL(rc, SUCCESS, "close f2 failed");
00061
00062 f1 = open("FILE1", O_RDONLY);
00063 TEST_POSITIVE(f1, "Unable to open FILE1, after Close");
00064
00065 f2 = open("FILE2", O_RDONLY);
00066 TEST_POSITIVE(f1, "Unable to open FILE2, after Close");
00067
00068 TEST_NOT_EQUAL(f1, f2, "fd f1 == f2");
00069
00070 rc = read(f1, (char *) &intbuf, sizeof(intbuf));
00071 TEST_EQUAL(rc, sizeof(intbuf),
00072 "read from f1 does not read/return proper value");
00073 TEST_EQUAL(intbuf, i,
00074 "read from f1 did not get correct value");
00075
00076 rc = read(f2, (char *) &intbuf, sizeof(intbuf));
00077 TEST_EQUAL(rc, sizeof(j), "read from f2 does not read/return proper value");
00078 TEST_EQUAL(intbuf, j, "read from f2 did not get correct value");
00079
00080 TEST_STATS();
00081
00082 exit(0);
00083 }
00084