E
eoindeb
I am trying to create a directory on Solaris using the mkdir()
function. This works fine when I pass a string literal ("/etc/hosts")
to mkdir, but if I try passing a directory pointer to mkdir, it returns
a -1 error. The directory error works fine with fopen - does anyone
know what I am doing wrong?? Here's a snippet of the code:
int Check_Directory() //check for existence of directory - if not
there, create the file
{
int status, ret = 0;
char * directory;
directory = Directory(); //returns a char pointer - changes
depending on user input
FILE * infile, *outfile ;
infile = fopen (directory, "r");
if (infile) //no need to create directory
{
ret = 1; //the directory does exist
fclose( infile);
}
else
{
status = mkdir (directory, 0777);
printf("%i",status);
outfile = fopen (directory, "w");
fprintf(outfile,"%s","testing");
fclose (outfile);
}
return ret;
}
function. This works fine when I pass a string literal ("/etc/hosts")
to mkdir, but if I try passing a directory pointer to mkdir, it returns
a -1 error. The directory error works fine with fopen - does anyone
know what I am doing wrong?? Here's a snippet of the code:
int Check_Directory() //check for existence of directory - if not
there, create the file
{
int status, ret = 0;
char * directory;
directory = Directory(); //returns a char pointer - changes
depending on user input
FILE * infile, *outfile ;
infile = fopen (directory, "r");
if (infile) //no need to create directory
{
ret = 1; //the directory does exist
fclose( infile);
}
else
{
status = mkdir (directory, 0777);
printf("%i",status);
outfile = fopen (directory, "w");
fprintf(outfile,"%s","testing");
fclose (outfile);
}
return ret;
}