Wednesday, 2 October 2013

open() system call in C with char array as path appending ? to filename

open() system call in C with char array as path appending ? to filename

I am trying to open (and simultaneously create) a file in C, using a
character array as the path name I pass in which is stored within a node
structure. When I do this, it is appending a question mark to the file
name.
The array specifying the file name is defined as follows:
#define MAX_LENGTH 1024
typedef struct node {
...
char input[MAX_LENGTH]; // filename
...
}
When I initially put the program name in the node structure, I use
makeargv and strcpy as follows:
char **strings;
makeargv(s,":",&strings;
strcpy(n->input,strings[2]);
When I open the file, I try to redirect stdin to it as follows:
char **argumentList;
makeargv(nodes[i]->prog," ",&argumentList);
if (strcmp(nodes[i]->input, "stdin") != 0) {
char* input = nodes[i]->input;
int in = open(input, O_RDONLY);
dup2(in, 0);
int cl = close(in);
I am having trouble understanding if it is something to do with the way I
am passing the pathname in, the attempt to redirect to stdin, or something
else, and I'm having trouble figuring out exactly what the problem
is..could anyone point me in the right direction as to why this may be
happening?

No comments:

Post a Comment