diff --git a/file_system/gjb_S0101601GN_1.c b/file_system/gjb_S0101601GN_1.c new file mode 100644 index 0000000000000000000000000000000000000000..8b64f15d533d29f41d0987160f27021e193b1e3d --- /dev/null +++ b/file_system/gjb_S0101601GN_1.c @@ -0,0 +1,102 @@ +/********************************************************************************************************* +** +** GJB ???????? +** +** Copyright All Rights Reserved +** +**--------------??????-------------------------------------------------------------------------------- +** +** ?? ?? ??: gjb_S0101601GN_1.c +** +** ???????????: 2021 ?? 1 ?? 12 ?? +** +** ?? ??: ?????????????????????????????????????? +** ???????????????????????????????????????? +** ?????????????????????????????? +*********************************************************************************************************/ +#include +#include +#include +#include +#include +#include +#include + + +#include +#include +int main(int argc, char **argv) +{ + int fd; + char buf[32]; + int ret; + + /* + * ??????? + */ + fd = creat("./file", 0777); + if(fd < 0) { + printf("creat error"); + return -1; + + } else { + printf( "creat file success!"); + close(fd); + } + + fd = open("./file", O_RDWR, 0666); + + ret = write(fd, "this is a test", strlen("this is a test")); + if (ret < 0) { + printf("write file error"); + close(fd); + unlink("./file"); + return -1; + } else { + printf("write file success"); + } + + /* + * ?????????????????? + */ + fsync(fd); + lseek(fd, SEEK_SET, 0); + + /* + * ???????????????§Õ?????? + */ + ret = read(fd, buf, 32); + if (ret < 0) { + printf("read file error"); + close(fd); + unlink("./file"); + return -1; + + } else { + if (strncmp(buf, "this is a test", 14)) { + printf("check file content error"); + close(fd); + unlink("./file"); + return -1; + } + } + + close(fd); + + /* + * ?????????????, ?????????????-1 + */ + fd = creat("./file", 0777); + if (fd >= 0) { + printf( "creat same file test sucess!"); + } else { + printf("creat error"); + close(fd); + unlink("./file"); + return -1; + } + + unlink("./file"); + + return 0; +}