* msTmpFilename() * * Generate a Unique temporary filename. * * Returns char* which must be freed by caller. **********************************************************************/
| 1422 | * Returns char* which must be freed by caller. |
| 1423 | **********************************************************************/ |
| 1424 | char *msTmpFilename(const char *ext) |
| 1425 | { |
| 1426 | char *tmpFname; |
| 1427 | int tmpFnameBufsize; |
| 1428 | char *fullFname; |
| 1429 | char tmpId[128]; /* big enough for time + pid + ext */ |
| 1430 | |
| 1431 | snprintf(tmpId, sizeof(tmpId), "%lx_%x",(long)time(NULL),(int)getpid()); |
| 1432 | |
| 1433 | if (ext == NULL) ext = ""; |
| 1434 | tmpFnameBufsize = strlen(tmpId) + 10 + strlen(ext) + 1; |
| 1435 | tmpFname = (char*)msSmallMalloc(tmpFnameBufsize); |
| 1436 | |
| 1437 | msAcquireLock( TLOCK_TMPFILE ); |
| 1438 | snprintf(tmpFname, tmpFnameBufsize, "%s_%x.%s", tmpId, tmpCount++, ext); |
| 1439 | msReleaseLock( TLOCK_TMPFILE ); |
| 1440 | |
| 1441 | fullFname = strdup(tmpFname); |
| 1442 | free(tmpFname); |
| 1443 | |
| 1444 | return fullFname; |
| 1445 | } |
| 1446 | |
| 1447 | /** |
| 1448 | * Generic function to Initalize an image object. |
no test coverage detected