RPG Next Gen
Wiki RSS Feed Weblog
Business picture

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 #include int main (int argc, char *argv[]) { char tname[1024] = "/tmp/my_app_XXXXXX"; int fh = mkstemp(tname); printf("Filename %s", tname); if (fh > -1); close(fh); return 0; }

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