When sockets are created or files are opened/created in C, is the file descriptor that's assigned to the socket/file guaranteed to be the lowest-valued descriptor available? What does the C ... |
Of course, the immediate answer for most situations is "yes", and I am a firm believer that a process should correctly cleanup any resources it has allocated, but what I have ... |
I have a C program in which I create a tcl interpreter. I then open a file in the C program and want to pass it onto the tcl interpreter so ... |
If I have a buffer which contains the data of a file, how can I get a file descriptor from it?
This is a question derived from how to untar file ... |
my question is how would I change the program below so that it takes a file descriptor number on the command line rather than a file name? Any help would ... |
Does anyone see a problem with this, its not working saying bad file descriptor not sure why?
pipe(pipefd[0]);
if ((opid = fork()) == 0) {
dup2(pipefd[0][1],1);/*send to output*/
...
|
I have a multithreaded application that is opening and reading the same file (not writing). I am opening a different file descriptor for each thread (but they all point to the ... |
|
I'd like to know if a fd has data available for reading. I have tried ioctl with FIONREAD but that results in a "Operation not supported error". Any ideas?
|
stdinBackup = 4;
dup2(0, stdinBackup);
Currently I am doing the above to 'backup' stdin so that it can be restored from backup later after it has been redirected somewhere ... |
From what I have been reading on The Open Group website on fcntl, open, read, and write, I get the impression that whether ... |
I need to execute a file when I only know the descriptor. It is also possible that there are no links to the file so finding out the name somehow is ... |
Is there any portable way (on POSIX systems) to determine if a file descriptor is seekable? My thought is to use lseek(fd, 0, SEEK_CUR); and check if the return value is ... |
This is my code of function that wants to read file:
int sendByByte(int filed,int sockfd,int filesize)
{
int i=0;
int sent=0;
char buf[BUFSIZE];
while(i<filesize)
{
printf("fd is : %d\n",filed);
printf("i: %d\n",i);
...
|
I have an implementation of a bi-directional message channel which, to reduce overhead, I implemented as a couple of circular buffers of messages. To write from one end to the other ... |
I have a question with strcpy() function. What I am trying to do is the user enters a file name and I basicly open the file, gets contents and create copy ... |
I've about got my practice implementation of a Unix shell done, except I'm having an issue with implementing cat when its output is to a file; IE: cat foo.txt > bar.txt ... |
For a homework assignment I have to write a basic shell including redirection. The program uses readline to prompt for input, parses the input string, and breaks it down into the ... |
I open a file in program A. Its file descriptor is 3. Using fork followed by an execve I execute another program B, where I immediately open another file. This files ... |
I want to create a file descriptor in C whose value i will specify in code.
I have a integer variable which specifies the value of file descriptor to be created. For ... |
I'm learning about file descriptors and I wrote this code:
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
int fdrd, fdwr, fdwt;
char c;
main (int argc, char *argv[]) {
if((fdwt = open("output", O_CREAT, 0777)) ...
|
So, for my final year project, I'm using Video4Linux2 to pull YUV420 images from a camera, parse them through to x264 (which uses these images natively), and then send the encoded ... |
I'm opening a stream with funopen
FILE *fin = funopen(cookie, readfn, NULL, NULL, closefn);
if (fin == NULL)
{
handle_error();
return -1;
}
int fdin = fileno(fin);
The call to funopen ... |
I am wondering how I can pass a file descriptor thru the execve command and then access it on the other side. I know that I can use dup2 to ... |
I'm implementing a simple protocol to do file transfer between 2 PC's over serial port and I'm getting a weird error.
On the main I call a function "llopen":
int
llopen(int ...
|
I am trying to make a logger for a program. For that reason I am having a second child process that is getting the parent's stdout via a pipe and using ... |
My memory is really fuzzy on this topic, but I think I've accomplished something like this in the past by setting a timer, then calling read(). Then if the timer expires you get an interrupt, which makes the read fail, setting errno appropriately. That way you can just start the read and if the socket is closed you'll get that error ... |
By file descriptor do you mean a C language FILE handle or one of those unix style integers used for IO? (I'm not sure what windows uses in this case.) In C++, there is a good and is_open method for checking valid streams. One technique is to just do what you really want to do with the IO channel (i.e read, ... |
Hi, I trying to make a program with one thread sending a message to a message queue and the other receiving and printing it. This is what I've written so far: Code: #include #include #include #include #include #include #include #include #include #define MQUEUE_NAME "/mqueue" pthread_t send_thread, receive_thread; pthread_mutex_t mtx = PTHREAD_MUTEX_INITIALIZER; struct ... |
|
hi friends, its all code, but not getting why it is telling wrong descriptor. Code: 1 //redirecting output of ls -l command to wc, with help of tmp file 2 3 #include 4 #include 5 6 7 void main() 8 { 9 int fd ; 10 switch(fork()) 11 { 12 default : break ; 13 14 case -1 : fprintf(stderr, "system ... |
struct hostent *he; struct sockaddr_in server; int sockfd; /* resolve localhost to an IP (should be 127.0.0.1) */ if ((he = gethostbyname("nems")) == NULL) { puts("error resolving hostname.."); exit(1); } /* * copy the network address part of the structure to the * sockaddr_in structure which is passed to connect() */ memcpy(&server.sin_addr, he->h_addr_list[0], he->h_length); server.sin_family = AF_INET; server.sin_port = htons(1514); /* ... |
I am using the open() function to get a file descriptor for a certain file, and I want to get the current file position given this file descriptor. Is there any way to access the file position else than using the tell() function as it's not supported in the environment I am using. Regards, Rami Henein. |
fdDBG = NULL; if (argc > 1 ) { int i; for (i=0 ; i< argc; i++) { if ( strncmp(argv[i],"-f",2) == 0 ) { i=i+1; fdDBG = fopen(argv[i],"w"); if (fdDBG == NULL) { fdDBG = fdopen(2,"a"); #ifdef DEBUG pthread_mutex_lock(&dbg_mutex); fprintf(fdDBG,"%s Unable to open debug message file %s\nUsing stderr instead.\n",oStr,argv[i] ); pthread_mutex_unlock(&dbg_mutex); #endif } } } } if (fdDBG == NULL) ... |
Hi, I'm facing the following problem: I'm writing some code in a server-type environment. The server, when it gets a new connection, maps the socket file descriptor of the connecting client to stdin and stdout using dup2(). In my function, I want to map stdin and stdout to a different file descriptor (a temporary file) while not losing the client's file ... |
|
Helloin socket programming, how can I get the file decriptor for a remote client? Let me elucidateI have a server, two clients are suppose to connect to that server and pass message between them. I am using UDP. From a client, the message goes to the server and the server sends the message to the other client. The clients instantiates new ... |