diff options
author | tradke <tradke@bfcf8e34-485d-4d46-a995-1fd6fa6fb178> | 2004-06-20 12:45:46 +0000 |
---|---|---|
committer | tradke <tradke@bfcf8e34-485d-4d46-a995-1fd6fa6fb178> | 2004-06-20 12:45:46 +0000 |
commit | c3bcd6f915b02611aaebe2a2ec68ade9c161c0c3 (patch) | |
tree | dbc87f4507bd25ca8efb82cb0b6638c91313dfca | |
parent | 0b5bbc6bd07a65e81c010be0cd7d2425b464af96 (diff) |
Use mkstemp(3) if available.
This closes PR CactusPUGHIO 1462: "IsoSurfacer uses tmpnam()".
git-svn-id: http://svn.cactuscode.org/arrangements/CactusPUGHIO/IsoSurfacer/trunk@81 bfcf8e34-485d-4d46-a995-1fd6fa6fb178
-rw-r--r-- | src/Sockets.c | 23 |
1 files changed, 10 insertions, 13 deletions
diff --git a/src/Sockets.c b/src/Sockets.c index 3d51641..33c8162 100644 --- a/src/Sockets.c +++ b/src/Sockets.c @@ -143,7 +143,8 @@ static isoSocket *datasocklist = NULL; static int chosen_controlport = 0; static int chosen_dataport = 0; -static char *advertised_filename = NULL; +#define FILENAME_TEMPLATE "fileXXXXXX" +static char *advertised_filename = FILENAME_TEMPLATE; /******************************************************************** @@ -209,13 +210,12 @@ int Iso_SetupServer(const cGH *GH,isosurfacerGH *myGH,int dataport, int controlp " host '%s' control port %d data port %d", hostname, chosen_controlport, chosen_dataport); - advertised_file_fd = NULL; - advertised_filename = (char *) malloc (L_tmpnam); - if (advertised_filename && tmpnam (advertised_filename)) - { - advertised_file_fd = fopen (advertised_filename, "w"); - } - +#ifdef HAVE_MKSTEMP + advertised_file_fd = fdopen (mkstemp (advertised_filename), "w"); +#else + advertised_file_fd = tmpnam (advertised_filename) ? + fopen (advertised_filename, "w") : NULL; +#endif if (advertised_file_fd) { fprintf (advertised_file_fd, "Hostname: %s\n", hostname); @@ -236,8 +236,6 @@ int Iso_SetupServer(const cGH *GH,isosurfacerGH *myGH,int dataport, int controlp { CCTK_WARN (2, "Couldn't create unique temporary file ! " "Isosurfacer data streaming was not advertised."); - free (advertised_filename); - advertised_filename = NULL; } return (0); @@ -265,10 +263,9 @@ int Iso_ShutdownServer(void) } /* remove advertised file and free filename */ - if (advertised_filename) + if (strcmp (advertised_filename, FILENAME_TEMPLATE)) { remove (advertised_filename); - free (advertised_filename); } return (0); @@ -765,7 +762,7 @@ static isoSocket *SocketCreate(unsigned long int filedes, isoSocket **list) { isoSocket *this; - this = (isoSocket *)malloc(sizeof (isoSocket)); + this = malloc(sizeof (isoSocket)); if(this) { |