文件操作中的FLAG(O_RDONLY,O_WRONLY )的值

本文详细解释了C语言中用于文件操作的各种标志符,包括读写模式、创建、排除等,通过具体的十六进制数值展示每个标志的作用。

 

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
void main(void)
{
        printf("O_ACCMODE       %08x\n",  O_ACCMODE               ) ; 
        printf("O_RDONLY        %08x\n",  O_RDONLY                ) ; 
        printf("O_WRONLY        %08x\n",  O_WRONLY                ) ; 
        printf("O_RDWR          %08x\n",  O_RDWR                  ) ; 
        printf("O_CREAT         %08x\n",  O_CREAT                 ) ; 
        printf("O_EXCL          %08x\n",  O_EXCL                  ) ; 
        printf("O_NOCTTY        %08x\n",  O_NOCTTY                ) ; 
        printf("O_TRUNC         %08x\n",  O_TRUNC                 ) ; 
        printf("O_APPEND        %08x\n",  O_APPEND                ) ; 
        printf("O_NONBLOCK      %08x\n",  O_NONBLOCK              ) ; 
        printf("O_DSYNC         %08x\n",  O_DSYNC                 ) ; 
        printf("FASYNC          %08x\n",  FASYNC                  ) ; 
        printf("O_NOFOLLOW      %08x\n",  O_NOFOLLOW              ) ; 

}
/*
O_ACCMODE       00000003
O_RDONLY        00000000
O_WRONLY        00000001
O_RDWR          00000002
O_CREAT         00000040
O_EXCL          00000080
O_NOCTTY        00000100
O_TRUNC         00000200
O_APPEND        00000400
O_NONBLOCK      00000800
O_DSYNC         00001000
FASYNC          00002000
O_NOFOLLOW      00020000
*/

 

转载于:https://www.cnblogs.com/mylinux/p/5301708.html

#include <stdio.h> #include <stdlib.h> #include <stdbool.h> #include <string.h> #include <sys/wait.h> #include <sys/types.h> #include <sys/stat.h> #include <errno.h> #include <unistd.h> // for execlp #include <mqueue.h> // for mq #include "settings.h" #include "messages.h" char client2dealer_name[30]; int groupnumber = 16; pid_t processID; mqd_t Req_queue_X; MQ_REQUEST_MESSAGE req; int main (int argc, char * argv[]) { struct mq_attr attr; attr.mq_maxmsg = MQ_MAX_MESSAGES; attr.mq_msgsize = sizeof (MQ_REQUEST_MESSAGE); sprintf (client2dealer_name, "/Req_queue_%d", groupnumber); mq_unlink(client2dealer_name); Req_queue_X = mq_open (client2dealer_name, O_RDONLY | O_CREAT | O_EXCL, 0600, &attr); if(Req_queue_X == -1) { perror("Channel creation failed!"); } getattr(Req_queue_X); processID = fork(); if (processID < 0) { perror("fork() failed"); exit (1); } else if (processID == 0) { // child-stuff execlp("./client", "client", client2dealer_name, NULL); perror("execlp failed"); exit (0); } while (1) { int status; pid_t result = waitpid(processID, &status, WNOHANG); // Non-blocking check if (result > 0) { printf("Client terminated\n"); break; } ssize_t size = mq_receive(Req_queue_X, (char*)&req, sizeof(MQ_REQUEST_MESSAGE), 0); if (size == -1) { perror("Receiving failed \n"); } else if ( size == sizeof(MQ_REQUEST_MESSAGE)) { if (req.serv_type == 1 || req.serv_type == 2) { printf("Received message with id %d, type %d and value %d\n", req.req_id, req.serv_type, req.input); } else if (req.serv_type == 0) { printf("...\n"); } } else { perror("mq_receive failed partially \n"); } sleep(1); printf("I'm still alive \n"); } printf("loop ends \n"); waitpid(processID, NULL, 0); mq_close(Req_queue_X); mq_unlink(client2dealer_name); } 帮我分析下问题在哪里
最新发布
03-14
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值