Hi
could you please help me with debugging my code.
I've define :char write_buffer[]="COLORTERM=gnome-terminal";
the out file is:environment
Q - why the environment file content is:
COLORTERM=gnome-terminalCCOLORTERM=gnome-terminalOLORTERM=gnome-terminalCOLORTERCOLORTERM=gnome-terminal$
I'll expect it to be:COLORTERM=gnome-terminal
thanks in advanced
Code:
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
#include <stdlib.h> //used for exit()
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
#include <assert.h>
#include <error.h>
//prototypes
/*******************************************************************************/
int main()
{
#define WorkPATH "//My_solution//environment"
#define file "environment"
int fd,length=0;
int size;
char read_buffer[30];
char write_buffer[]="COLORTERM=gnome-terminal";
//open the file, if it doesn't exist create it with the following permission access
fd = open (WorkPATH,/* O_RDONLY */ O_RDWR |O_CREAT,0775);
if (fd == -1)
{
/* The open failed. Print an error message and exit. */
printf("error opening file: \n");
exit(-1);
}
/* Read the size of the data in the file. */
//Use the systems calls in order to read from $path via read only permissions
length = read (fd, read_buffer, sizeof (write_buffer));
//Try to write to it ,with the same read only permissions
length = write (fd, write_buffer, strlen (write_buffer));
printf("The file Content is: \n");
system("cat //My_solution//environment");
// Close the file descriptor,
close (fd);
}