file-descriptor

Android ParcelFileDescriptor.createPipe() for Froyo?

落花浮王杯 提交于 2019-12-01 19:58:21
I have a need to use ParcelFileDescriptor.createPipe() , but I would still like to target API 8/Froyo. This function requires API 9/Gingerbread. I have read that there are compatibility kits that allow newer API functions to be used on the older OS versions, but know nothing about them. Is that an option here? If not, what would be the cleanest method for going about duplicating this functionality? I have considered using fromSocket() and making a simple network connection over the loopback interface, but that seems like more overhead than is needed, if there were a simpler way. Any thoughts

fopen and getting system file descriptor

血红的双手。 提交于 2019-12-01 18:51:24
I want to get a system file descriptor of the returned resource when I open a file using open. I assume the descriptor is an INT value which is normally inside /dev/fd/ I know that I can read from the descriptor by doing something like: fread("php://fd/$descriptor", $buflen); But now I want to get the descriptor for a resource opened by PHP's fopen (). Is there a way? This is a rather hacky way around it but it works! function fd($realpath) { $dir = '/proc/self/fd/'; if ($dh = opendir($dir)) { while (($file = readdir($dh)) !== false) { $filename = $dir . $file; if (filetype($filename) == 'link

Why does bash behave differently, when it is called as sh?

不打扰是莪最后的温柔 提交于 2019-12-01 12:29:49
问题 I have an ubuntu machine with default shell set to bash and both ways to the binary in $PATH: $ which bash /bin/bash $ which sh /bin/sh $ ll /bin/sh lrwxrwxrwx 1 root root 4 Mar 6 2013 /bin/sh -> bash* But when I try to call a script that uses the inline file descriptor (that only bash can handle, but not sh) both calls behave differently: $ . ./inline-pipe reached $ bash ./inline-pipe reached $ sh ./inline-pipe ./inline-pipe: line 6: syntax error near unexpected token `<' ./inline-pipe: line

When is FileDescriptor closed?

删除回忆录丶 提交于 2019-12-01 00:41:56
My app needs to do the following: Open a FileInputStream , and obtain the underlying FileDescriptor (via getFd() ) Create new FileInputStream objects based on the above FileDescriptor So far, I only needed one FileDescriptor , so I used to close it by calling close() on the original stream (i.e. on the stream which getFd() I called). I use it because some Android API methods have such a parameter. Now that I will have more FileInputStream objects at the same time, when will the FileDescriptor be closed? (My guess: when all FileInputStream objects are closed?) I belive you are right. A small

Difference between fclose and close

杀马特。学长 韩版系。学妹 提交于 2019-11-30 20:13:19
If I fopen a file, what's the difference between calling fclose or close and which one should I use? If forked children have access to the file as well, what should they do when they are finished with the file? Gangadhar fclose() is function related with file streams . When you open file with the help of fopen() and assign stream to FILE *ptr . Then you will use fclose() to close the opened file. close() is a function related with file descriptors . When you open file with the help of open() and assign descriptor to int fd . Then you will use close() to close the opened file. The functions

C: how to redirect stderr from System-command to stdout or file?

核能气质少年 提交于 2019-11-30 19:26:00
The shell command $ avrdude -c usbtiny outputs text to stderr. I cannot read it with commmands such as head-less-more cos it is not stdout. I want the text to stdout or to a file. How can I do it in C? I have tried to solve the problem by my last question but still unsolved. I've not tried something like this in OpenBSD, but in at least a few *nix-like systems, you can do this using dup2 . #include <unistd.h> #include <stdio.h> int main(void) { fprintf(stderr, "This goes to stderr\n"); dup2(1, 2); //redirects stderr to stdout below this line. fprintf(stderr, "This goes to stdout\n"); } The

Empty or “flush” a file descriptor without read()?

孤街浪徒 提交于 2019-11-30 18:00:45
(Note: This is not a question of how to flush a write() . This is the other end of it, so to speak.) Is it possible to empty a file descriptor that has data to be read in it without having to read() it? You might not be interested in the data, and reading it all would therefore waste space and cycles you might have better uses for. If it is not possible in POSIX, do any operating systems have any non-portable ways to do this? UPDATE: Please note that I'm talking about file descriptors , not streams. Streams have fclean available, which flushes the write buffer, and returns the read buffer back

Difference between fclose and close

蹲街弑〆低调 提交于 2019-11-30 15:20:53
问题 If I fopen a file, what's the difference between calling fclose or close and which one should I use? If forked children have access to the file as well, what should they do when they are finished with the file? 回答1: fclose() is function related with file streams . When you open file with the help of fopen() and assign stream to FILE *ptr . Then you will use fclose() to close the opened file. close() is a function related with file descriptors . When you open file with the help of open() and

Why FD_SET/FD_ZERO for select() inside of loop?

自作多情 提交于 2019-11-30 10:39:55
问题 I am using the select function for communication between my sockets. I have a while loop and I do - while(!done) { FD_ZERO(&read_flags); FD_ZERO(&write_flags); FD_SET(comm_fd1, &read_flags); FD_SET(comm_fd2, &read_flags); FD_SET(STDIN_FILENO, &read_flags); FD_SET(comm_fd1, &write_flags); FD_SET(comm_fd2, &write_flags); FD_SET(STDIN_FILENO, &write_flags); //call select sel = select(comm_fd1+comm_fd2+1, &read_flags, &write_flags, (fd_set*)0, &waitd); and the same with different variables on the

Writing to child process file descriptor

蓝咒 提交于 2019-11-30 10:27:31
I have a program "Sample" which takes input both from stdin and a non-standard file descriptor (3 or 4) as shown below int pfds[2]; pipe(pfds); printf("%s","\nEnter input for stdin"); read(0, pO, 5); printf("\nEnter input for fds 3"); read(pfds[0], pX, 5); printf("\nOutput stout"); write(1, pO, strlen(pO)); printf("\nOutput fd 4"); write(pfds[1], pX, strlen(pX)); Now i have another program "Operator" which executes the above program(Sample) in a child process using execv. Now what i want is to send input to "Sample" through the "Operator" . After forking the child process, but before calling