comparison src/util.c @ 3233:96e215745dc0

[gaim-migrate @ 3250] Changed gaim_mkstemp() to use GLib's g_get_tmp_dir() at Sean's suggestion. committer: Tailor Script <tailor@pidgin.im>
author Jim Seymour <jseymour>
date Wed, 08 May 2002 00:21:26 +0000
parents cf460a8c859c
children 86fdd015f40e
comparison
equal deleted inserted replaced
3232:cf460a8c859c 3233:96e215745dc0
1279 */ 1279 */
1280 static const char *gaim_mkstemp_templ = {"gaimXXXXXX"}; 1280 static const char *gaim_mkstemp_templ = {"gaimXXXXXX"};
1281 1281
1282 FILE *gaim_mkstemp(gchar **fpath) 1282 FILE *gaim_mkstemp(gchar **fpath)
1283 { 1283 {
1284 static char *tmpdir = NULL; 1284 gchar *tmpdir;
1285 int fd; 1285 int fd;
1286 FILE *fp = NULL; 1286 FILE *fp = NULL;
1287 1287
1288 if(!tmpdir) { 1288 if((tmpdir = g_get_tmp_dir()) != NULL) {
1289 if((tmpdir = tempnam(NULL, NULL)) == NULL) {
1290 debug_printf("Error: tempnam() failed, error: %d\n", errno);
1291 } else {
1292 char *t = strrchr(tmpdir, '/');
1293 *t = '\0';
1294 }
1295 }
1296
1297 if(tmpdir) {
1298 if((*fpath = g_strdup_printf("%s/%s", tmpdir, gaim_mkstemp_templ)) != NULL) { 1289 if((*fpath = g_strdup_printf("%s/%s", tmpdir, gaim_mkstemp_templ)) != NULL) {
1299 if((fd = mkstemp(*fpath)) == -1) { 1290 if((fd = mkstemp(*fpath)) == -1) {
1300 debug_printf("Error: Couldn't make \"%s\", error: %d\n", *fpath, errno); 1291 debug_printf("Error: Couldn't make \"%s\", error: %d\n", *fpath, errno);
1301 } else { 1292 } else {
1302 if((fp = fdopen(fd, "r+")) == NULL) { 1293 if((fp = fdopen(fd, "r+")) == NULL) {
1307 if(!fp) { 1298 if(!fp) {
1308 g_free(*fpath); 1299 g_free(*fpath);
1309 *fpath = NULL; 1300 *fpath = NULL;
1310 } 1301 }
1311 } 1302 }
1303 } else {
1304 debug_printf("Error: g_get_tmp_dir() failed in gaim_mkstemp()!\n");
1312 } 1305 }
1313 1306
1314 return fp; 1307 return fp;
1315 } 1308 }