so i'm trying to write this function that gets an argument that tells it whether to display the input to the screen or to redirect it to some file. I'm doing it by redirecting the stdout part. For some reason, the flags in the open() function are not recognized, even though i did #include as required.
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/wait.h>
#define TRUE 1
#define FALSE 0
void writer(char* fileName);
void writerEmpty();
void writer(char* fileName)
{
char buffer[64];
int size = 64;
int fd;
read(0, buffer, size);
if (!strcmp("std", fileName))
{
close(1);
fd = open(fileName, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR);
}
write(1, buffer, size);
}
The visual studio doesn't recognize the S_IRUSR
and S_IWUSR
flags, and when I don't use them at all, open() returns -1 (error).
Help? someone? :)