mkstemp
About
From the Linux man page:
The mkstemp() function generates a unique temporary filename from template.
The last six characters of template must be XXXXXX and these are replaced
with a string that makes the filename unique. The file is then created with
mode read/write and permissions 0600. Since it will be modified, template
must not be a string constant, but should be declared as a character array.
The file is opened with the open() O_EXCL flag, guaranteeing that
when mkstemp() returns successfully we are the only user.
On success, the mkstemp() function returns the file descriptor of the
temporary file. On error, -1 is returned, and errno is set appropriately.
C header
int mkstemp(char *template);
C example
/* Includes */
#include
RPG example
/** * \brief mkstemp() test * * \author Mihael Schmidt * \date 30.05.2010 */ H dftactgrp(*no) actgrp(*caller) bnddir('MY_BND_DIR') /copy LIBC_H /copy IFSIO_H D mkstemp PR 10I 0 extproc('mkstemp') D tname * value D fh S 10I 0 D template S 50A /free template = '/tmp/testXXXXXX' + x'00'; fh = mkstemp(%addr(template)); dsply template; callp close(fh); unlink(template); *inlr = *on; /end-free
Source code
- STDLIB - mkstemp module
- IFSIO_H - copybook C I/O functinos
- LIBC_H - copybook C functions