热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

F_GETPIPE_SZ在C中返回-1。-F_GETPIPE_SZreturns-1inC

WhywouldF_GETPIPE_SZreturn-1?Itsoundslikeanerror,butIcantfindanymentionofwhaterro

Why would F_GETPIPE_SZ return -1? It sounds like an error, but I can't find any mention of what error it is, or, more importantly, what I'm supposed to do to not get the error.

为什么F_GETPIPE_SZ返回-1?这听起来像是一个错误,但我找不到任何关于它是什么错误的,或者更重要的是,我应该做些什么来避免错误。

I'm running Raspbian on a Raspberry Pi, for what it's worth. I haven't tried the code on my desktop Debian yet. As far as I can tell, I'm following the textbook F_GETPIPE_SZ example. Am I missing something?

我在树莓派上运行的是Raspbian,它值多少钱。我还没试过桌面Debian的代码。据我所知,我是按照课本F_GETPIPE_SZ的例子。我遗漏了什么东西?

#define _GNU_SOURCE
#include 
#include 
#include 
#include 

int main(int argc, char **argv)
{
  int fd, pipesize;
  fd = mkfifo("/tmp/audio-fifo",0666);
  //  fcntl(fd, F_SETPIPE_SZ, 4096);
  pipesize = fcntl(fd, F_GETPIPE_SZ);
  printf("Pipe size: %d\n", pipesize);
  return 0;
}

1 个解决方案

#1


0  

mkfifo will just create the special file for you. It will return either 0 on success or an errno if an error occoured.

mkfifo将为您创建特殊文件。它将在成功或错误occoured时返回0。

What you have to do after you created the pipe using mkfifo is open that file with open. After that you will have a valid file descriptor to pass fnctl (as long as none of these functions returned an error!).

在使用mkfifo创建管道之后,您需要做的是打开该文件。在此之后,您将有一个有效的文件描述符来传递fnctl(只要这些函数没有返回一个错误!)

So basically what you are missing is the open command.

所以基本上你缺少的是打开的命令。


推荐阅读
author-avatar
小傲骄FMJ
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有