fixing the open file arguments in the execv func
This commit is contained in:
parent
e0b8e9ddc5
commit
1091e2413f
1 changed files with 2 additions and 2 deletions
4
main.c
4
main.c
|
@ -120,10 +120,10 @@ int main()
|
||||||
{
|
{
|
||||||
int i_lastArg = getFileNameIndex(args);
|
int i_lastArg = getFileNameIndex(args);
|
||||||
char* fileName = (char *)malloc(strlen(args[i_lastArg])*sizeof(char));
|
char* fileName = (char *)malloc(strlen(args[i_lastArg])*sizeof(char));
|
||||||
strcpy(fileName, args[i_lastArg]);
|
strcpy(fileName, args[i_lastArg]); //saving file name before cleaning the array
|
||||||
freeRemainderInArr(args, i_lastArg);
|
freeRemainderInArr(args, i_lastArg);
|
||||||
|
|
||||||
int fd = open(fileName, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
|
int fd = open(fileName, O_RDWR | O_CREAT | O_TRUNC);
|
||||||
if(fd >= 0)
|
if(fd >= 0)
|
||||||
{
|
{
|
||||||
dup2(fd, 1); // make stdout go to file
|
dup2(fd, 1); // make stdout go to file
|
||||||
|
|
Loading…
Reference in a new issue