sem_open can't open a name with directory

 

sem_open can't open a name with directory


  • From: "Xiong, Crystal" <crystal xiong intel com>
  • To: phil-list redhat com
  • Subject: sem_open can't open a name with directory
  • Date: Tue, 28 Jan 2003 21:00:54 +0800

Title: Message
If define name as "/tmp/xxxx", and invoke sem_open(name, flag...), sem_open will failed with "No such file or directory". 
 
Looked into the code sem_open.c, the reason is that the name ("/tmp/xxxx")will map to /dev/shm/sem.tmp/xxxx, but sem.tmp directory is not there, so there will be an error.
 
I think in sem_open.c, it maybe needs a check of whether name has more slash characters other than the leading slash character.
If it has, mkdir the related directory before rename operation (sem_open.c:234), such as the following:
    tmpname = strrchr(finalname, '/');  // get the file name without directory
    strncpy(pathname, finalname, strlen(finalname) - strlen(tmpname)); // get the directory path
    mkdir(pathname, 0777)
 
To the POSIX std, it says the interpretation of slash characters other than the leading slash character in name is implementaion defined. I think it will be more friendly to allow the user using a name with directory.
 
Thanks,
Crystal
------------------------------------------------------------------------------------------------
This is only my personal opinion.
 
Crystal Xiong
Intel China Software Lab
face_manage.c: In function 'fr_loop': face_manage.c:657:16: error: implicit declaration of function 'shm_open'; did you mean 'sem_open'? [-Werror=implicit-function-declaration] 657 | int shm_fd = shm_open(SHM_NAME, O_CREAT | O_RDWR, 0666); | ^~~~~~~~ | sem_open face_manage.c:670:23: error: implicit declaration of function 'mmap' [-Werror=implicit-function-declaration] 670 | RECT *shared_rect = mmap(NULL, sizeof(RECT), PROT_READ | PROT_WRITE, MAP_SHARED, shm_fd, 0); | ^~~~ face_manage.c:670:48: error: 'PROT_READ' undeclared (first use in this function) 670 | RECT *shared_rect = mmap(NULL, sizeof(RECT), PROT_READ | PROT_WRITE, MAP_SHARED, shm_fd, 0); | ^~~~~~~~~ face_manage.c:670:48: note: each undeclared identifier is reported only once for each function it appears in face_manage.c:670:60: error: 'PROT_WRITE' undeclared (first use in this function) 670 | RECT *shared_rect = mmap(NULL, sizeof(RECT), PROT_READ | PROT_WRITE, MAP_SHARED, shm_fd, 0); | ^~~~~~~~~~ face_manage.c:670:72: error: 'MAP_SHARED' undeclared (first use in this function) 670 | RECT *shared_rect = mmap(NULL, sizeof(RECT), PROT_READ | PROT_WRITE, MAP_SHARED, shm_fd, 0); | ^~~~~~~~~~ face_manage.c:671:22: error: 'MAP_FAILED' undeclared (first use in this function); did you mean 'SEM_FAILED'? 671 | if (shared_rect == MAP_FAILED) { | ^~~~~~~~~~ | SEM_FAILED face_manage.c:687:3: error: implicit declaration of function 'munmap' [-Werror=implicit-function-declaration] 687 | munmap(shared_rect, sizeof(RECT)); | ^~~~~~ cc1: all warnings being treated as errors <builtin>: recipe for target 'face_manage.o' failed make[5]: *** [face_manage.o] Error 1 make[5]: Leaving directory '/home/fuyu1/code/nt9853x
最新发布
12-01
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值