入来接分

进来接分

#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
//#include <unistd.h>

char buf1[] = "abcdefghij";
char buf2[] = "ABCDEFGHIJ";

int main()
{
int fd;

//if( fd = creat("file.hole", O_RDWR) == -1)
if( fd = creat("file.hole", O_WRONLY) == -1)
perror("creat fall\n");
#if 1
if(write(fd, buf1, 10) != 10)
perror("buf1 write fall\n");

if(lseek(fd, 40, SEEK_SET) == -1)
perror("\nlseek falli");
/*  offset now = 40 */

if(write(fd, buf2, 10) != 10)
perror("\nbuf2 write fall\n");
/*  offset now = 50 */
#endif
putchar(10);

return 0;
}

入来接分
很奇怪的现象,以RDWR打开文件权限为----------
                             以WRONLY打开文件权限为---------x




------解决方案--------------------
在你的程序的原有基础上加上<io.h>和<errno.h>头文件,用上面那两个标志位试下。行不行试下就知道了。
------解决方案--------------------
if( fd = creat("file.hole", O_WRONLY) == -1),话说这不是少了个括号么-。-,这fd要不是0要不就是1呀
------解决方案--------------------
看了一下手册,你的参数值的确是取错了.函数原型int creat(const char *pathname, mode_t mode);mode的取值是
              S_IRWXU, 00700 user (file owner) has  read,  write  and  execute permission

              S_IRUSR  00400 user has read permission

              S_IWUSR  00200 user has write permission

              S_IXUSR  00100 user has execute permission

              S_IRWXG  00070 group has read, write and execute permission

              S_IRGRP  00040 group has read permission

              S_IWGRP  00020 group has write permission

              S_IXGRP  00010 group has execute permission

              S_IRWXO  00007 others have read, write and execute permission

              S_IROTH  00004 others have read permission

              S_IWOTH  00002 others have write permission

              S_IXOTH  00001 others have execute permission