Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

tmpfile () returns NULL

96 views
Skip to first unread message

kzelec...@e3tech.local

unread,
Apr 22, 2013, 3:34:22 AM4/22/13
to
perror says "Permission denied"

kzelec...@e3tech.local

unread,
Apr 22, 2013, 3:49:40 AM4/22/13
to
(fopen (tmpnam (l_buf), "w+b")) fails as well (tmpnam returned "\s4h0.5").

U�ytkownik napisa� w wiadomo�ci grup
dyskusyjnych:kl2otr$40q$1...@news.icm.edu.pl...

perror says "Permission denied"

kzelec...@e3tech.local

unread,
Apr 22, 2013, 4:06:05 AM4/22/13
to
Here is the documentation you provided:

Function: tempnam _tempnam

Synopsis

#include <stdio.h>
char *_tempnam(char *s);

Error MR.c: C:\Program Files\MATLAB\R2012a\sys\lcc\include\stdio.h: 189
redeclaration of `_tempnam' previously declared at MR.c 1
char * _tempnam(char *, char *);


Description

_tempnam creates a temporary filename for use in another directory. This
filename is different from that of any existing file. The prefix argument
(??) is the prefix to the filename. _tempnam uses malloc to allocate space
for the filename; the program is responsible for freeing this space when it
is no longer needed. _tempnam looks for the file with the given name in the
following directories, listed in order of precedence.

WHAT DIRECTORIES?

Returns

A pointer to the name generated or NULL if this fails. Note that this
function is not an ANSI C library function.
(WHY SHOULD IT BE? ANSI did not envisage the situation when tmpnam is
useless!)

Example FOR tmpfile !!!

#include <stdio.h>
int main( void )
{
FILE *stream;
int i;
/* Create temporary files. */
for( i = 1; i <= 4; i++ )
{
if( (stream = tmpfile()) == NULL ) {ďż˝
perror( "Could not open new temporary file" );
break;
}
else
printf( "Temporary file %d was created", i );
}
/* Remove temporary files. */
printf( "%d temporary files deleted", _rmtmp() );
return 0;
}

U�ytkownik napisa� w wiadomo�ci grup
dyskusyjnych:kl2pqj$6cv$1...@news.icm.edu.pl...

jacob navia

unread,
Apr 23, 2013, 12:37:41 PM4/23/13
to
Le 22/04/13 10:06, kzelec...@e3tech.local a écrit :
>
> Użytkownik napisał w wiadomości grup
> dyskusyjnych:kl2otr$40q$1...@news.icm.edu.pl...
>
> perror says "Permission denied"

Please use an appropiate directory. If not, your files are created at
the root of the drive ( \tmpFOo6555 for instance).

You do not have any write access to the root directory, hence
"permission denied")


jacob navia

unread,
Apr 23, 2013, 3:55:46 PM4/23/13
to
Here is the source code of tmpnam.

What improvements ypu would do?

/*---------------------------------------------------------------------------*/
/* tmpnam() - create a unique temporary filename
*/
/*---------------------------------------------------------------------------*/
#include <windows.h>
#include <stdio.h>

char *tmpnam(char *string)
{
int r;
char lpPathBuffer[BUFSIZ];
static char path[BUFSIZ];

r = GetTempPath(BUFSIZ,lpPathBuffer);
if (r == 0 || r >= BUFSIZ) {
lpPathBuffer[0]= '.';
lpPathBuffer[1]=0;
}

if (string == NULL)
string = path;
r = GetTempFileName(lpPathBuffer,"TmP",0,string);
if (r == 0)
return NULL;
return string;
}

kzelec...@e3tech.local

unread,
Apr 24, 2013, 2:27:12 AM4/24/13
to
My call to tmpnam returned e.g. "\s4h0.5". This is inconsistent with your
code and what the stand-alone compiler returns so it is perhaps another
MATLAB problem.
Still, _tempnam is undocumented.

U�ytkownik "jacob navia" napisa� w wiadomo�ci grup
dyskusyjnych:kl6ovu$cfo$1...@speranza.aioe.org...
0 new messages