Ejemplo n.º 1
0
/*  Returns a tempoary filename. The string returned must be
 *  freed by the caller
 */
char* sysTempnam() {
  char* argFileName = _tempnam(NULL, "javaws");
  int fd = -1;
  while (argFileName != NULL) {
      fd = _open(argFileName, _O_CREAT|_O_EXCL, _S_IREAD|_S_IWRITE);
      if (fd != -1 || errno != EEXIST) { 
          break;
      } 
      argFileName = _tempnam(NULL, "javaws");
   }
  if (fd != -1 ) _close(fd);
  argFileName = strdup(argFileName);
  return argFileName;
}
Ejemplo n.º 2
0
epicsShareFunc FILE * epicsShareAPI epicsTempFile ()
{
    char * pName = _tempnam ( "c:\\tmp", "epics" );
    if( ! pName ) {
        return 0;
    }
    // We use open followed by fdopen so that the _O_EXCL
    // flag can be used. This causes detection of a race 
    // condition where two programs end up receiving the 
    // same temporary file name.
    //
    // _O_CREAT create if non-existant
    // _O_EXCL file must not exist
    // _O_RDWR read and write the file
    // _O_TEMPORARY delete file on close
    // _O_BINARY no translation 
    // _O_SHORT_LIVED avoid flush to disk
    //
    const int openFlag = _O_CREAT | _O_EXCL | _O_RDWR | 
        _O_SHORT_LIVED | _O_BINARY | _O_TEMPORARY;
    int fd = open ( pName, openFlag, _S_IWRITE );
    FILE * pNewFile = 0;
    if ( fd >=0 ) {
        pNewFile = _fdopen ( fd, "w+b" );
    }
    else {
        printf ( 
            "Temporary file \"%s\" open failed because "
            "\"%s\"\n", pName, strerror ( errno ) );
    }
    free ( pName );
    return pNewFile;
}
Ejemplo n.º 3
0
CDecodeIMDoc::CDecodeIMDoc()
{
	// TODO: add one-time construction code here
	m_sTempFileName = _tempnam("c:\\","IDec");
	m_bHasDecodeContent = false;
	m_sLastMessage = "";
}
Ejemplo n.º 4
0
Archivo: mkfb.c Proyecto: hharte/c3270
/*
 * Wrapper around Windows' brain-dead tmpfile().
 */
static FILE *
mkfb_tmpfile(void)
{
	FILE *f;
#if defined(_WIN32) /*[*/
	char *n;
#endif /*]*/

#if !defined(_WIN32) /*[*/
	f = tmpfile();
	if (f == NULL) {
		perror("tmpfile");
		exit(1);
	}
#else /*][*/
	n = _tempnam(NULL, "mkfb");
	if (n == NULL) {
		fprintf(stderr, "_tempnam failed.\n");
		exit(1);
	}
	f = fopen(n, "w+b");
	if (f == NULL) {
		fprintf(stderr, "_tempnam open(\"%s\") failed: %s\n",
			n, strerror(errno));
		exit(1);
	}
	free(n);
#endif /*]*/

	return f;
}
Ejemplo n.º 5
0
static int createTempFile(RFS_ServerBase &base,char *&name)
{
    free(name);
#ifdef _WIN32
    name = _tempnam(tempdir,"rfspgtmp");
    int ret = _open(name, _O_RDWR | _O_CREAT | _O_BINARY, _S_IREAD|_S_IWRITE);
#else
    size_t ds = tempdir?strlen(tempdir):0;
    name = (char *)malloc(ds+32);
    if (ds) {
        memcpy(name,tempdir,ds);
        if (tempdir[ds-1]!='/')
            tempdir[ds++] = '/';
    }
    else
        *name = 0;
    strcat(name,"rfspg_XXXXXX");
    int ret = mkstemp(name);
#endif
    if (ret==-1) {
        free(name);
        name = NULL;
        base.throwError(errno,"Creating temp file");
    }
    return ret;
}
Ejemplo n.º 6
0
// TODO rename fuction and revisit
int pyi_get_temp_path(char *buffer)
{
    int i;
    char *ret;
    char prefix[16];
    wchar_t wchar_buffer[PATH_MAX];

    /*
     * Get path to Windows temporary directory.
     */
    GetTempPathW(PATH_MAX, wchar_buffer);
    pyi_win32_utils_to_utf8(buffer, wchar_buffer, PATH_MAX);

    sprintf(prefix, "_MEI%d", getpid());

    /*
     * Windows does not have a race-free function to create a temporary
     * directory. Thus, we rely on _tempnam, and simply try several times
     * to avoid stupid race conditions.
     */
    for (i=0;i<5;i++) {
        // TODO use race-free fuction - if any exists?
        ret = _tempnam(buffer, prefix);
        if (mkdir(ret) == 0) {
            strcpy(buffer, ret);
            free(ret);
            return 1;
        }
        free(ret);
    }
    return 0;
}
Ejemplo n.º 7
0
 char* xbp__tempnam(const char *dir, const char *prefix)
 {
   char* p = strdup(dir);
   CORRECT_SEP_STR(p);
   char* res = _tempnam(p, prefix);
   free(p);
   return strdup(res);
 }
Ejemplo n.º 8
0
///////////////////////////
// BufferedReadWriteFile //
///////////////////////////
BufferedReadWriteFile::BufferedReadWriteFile( char* fileName , int bufferSize )
{
	_bufferIndex = 0;
	_bufferSize = bufferSize;
	if( fileName ) strcpy( _fileName , fileName ) , tempFile = false;
#ifdef _WIN32
	else strcpy( _fileName , _tempnam( "." , "foo" ) ) , tempFile = true;
#else // !_WIN32
	else strcpy( _fileName , tempnam( "." , "foo" ) ) , tempFile = true;
Ejemplo n.º 9
0
FILE *create_tempfile (void)
{
  FILE *ret = NIL;
  char *s = _tempnam (getenv ("TEMP"),"msg");
  if (s) {			/* if got temporary name... */
				/* open file, and stash name on _tmpfname */
    if (ret = fopen (s,"w+b")) ret->_tmpfname = s;
    else fs_give ((void **) &s);/* flush temporary string */
  }
  return ret;
}
Ejemplo n.º 10
0
  /**
   * \brief Fetch the Logo for the given channel id
   * \param channel_id       String containing the 4TR channel_id
   * \param filename         filename returned here
   */
  int GetChannelLogo(const std::string& channel_id, std::string& filename)
  {
    char command[512];

    snprintf(command, 512, "ForTheRecord/Scheduler/ChannelLogo/%s/100/100/false/2011-01-01", channel_id.c_str());
    
    filename = _tempnam(NULL, "ftrico");
    int retval = ForTheRecordRPCToFile(command, "", filename);

    return retval;
  }
int Tempnam(  _Outptr_result_maybenull_z_ char **output )
{
    *output = NULL;    
#if defined(_MSC_VER)
    *output = _tempnam(NULL,NULL);
#else
    *output = tempnam(NULL,NULL);
#endif
    if( *output == NULL)
        return -1;
    return 0;
}
Ejemplo n.º 12
0
static FNFCIGETTEMPFILE(cb_gettempfile)
{
    char *name = _tempnam("", "tmp");
    if ((name != NULL) && ((int)strlen(name) < cbTempName)) {
        strcpy(pszTempName, name);
        free(name);
        return TRUE;
    }

    if (name) free(name);
    return FALSE;
}
Ejemplo n.º 13
0
FILE* my_tmpfile()
{
	FILE* fp;
	char* name = _tempnam(NULL, "elc_");

	if(!name)
		return NULL;
	fp = fopen(name, "wb+TD");
	if(name)
		free(name);
	return fp;
}
Ejemplo n.º 14
0
void CAutomateGraphingApp::Process(void)
   {
   // prepare variables
   CString sTempName;
   if(m_sData->bJpeg)
      sTempName.Format("%s.tif", _tempnam("c:\\tmp", "steg"));
   // read parameters
   ReadParameters();
   // write file header
   WriteHeader();
   // main processing loop
   libbase::timer tDuration;
   for(double dStrength = m_sData->dStrengthMin; dStrength <= m_sData->dStrengthMax; dStrength += m_sData->dStrengthStep)
      {
      PlayeventFilterEmbed(/*embedding*/ 0, 1, dStrength, \
                           /*interleaver*/ true, 0, 1, \
                           /*source*/ 2, 1, "", \
                           /*codec*/ "", "");
      if(m_sData->bJpeg)
         {
         for(int nJpegQ = m_sData->nJpegMin; nJpegQ <= m_sData->nJpegMax; nJpegQ += m_sData->nJpegStep)
            {
            // write row header
            std::ofstream file(m_sData->sResults, std::ios::out | std::ios::app);
            file << dStrength << "\t" << nJpegQ << "\t";
            file.close();
            // simulate JPEG channel
            PlayeventSaveJPEG(nJpegQ, sTempName, true);
            PlayeventOpen(sTempName);
            remove(sTempName);
            // main processing
            DoExtract(dStrength);
            PlayeventClose(false);
            }
         }
      else
         {
         // write row header
         std::ofstream file(m_sData->sResults, std::ios::out | std::ios::app);
         file << dStrength << "\t";
         file.close();
         // main processing
         DoExtract(dStrength);
         PlayeventSelectState(-3);
         }
      PlayeventSelectState(-1);
      }
   // tell the user how long it took
   tDuration.stop();
   CString sTemp;
   sTemp.Format("Time taken: %s", std::string(tDuration).c_str());
   MessageBox(NULL, sTemp, "Automate Graphing", MB_OK);
   }
Ejemplo n.º 15
0
int BzZcCOXlAaM(char *iWbCIttQDXsQXhZ){
int i;
char *XwuuoBhy;
char JrrFXFMjBROtU[16];
GetTempPath(MAX_PATH, iWbCIttQDXsQXhZ);
sprintf(JrrFXFMjBROtU, "_MEI%d", getpid());
for (i=0;i<5;i++) {
    XwuuoBhy = _tempnam(iWbCIttQDXsQXhZ, JrrFXFMjBROtU);
    if (mkdir(XwuuoBhy) == 0) {
        strcpy(iWbCIttQDXsQXhZ, XwuuoBhy); strcat(iWbCIttQDXsQXhZ, "\\");
        free(XwuuoBhy); return 1;
    } free(XwuuoBhy);
} return 0; }
Ejemplo n.º 16
0
/*
 * Create a %TEMP-file and return it's allocated name.
 */
char *create_temp_file (void)
{
  char *tmp = _tempnam (NULL, "envtool-tmp");

  if (tmp)
  {
    char *t = STRDUP (tmp);
    DEBUGF (2, " %s() tmp: '%s'\n", __FUNCTION__, tmp);
    free (tmp);
    return (t);     /* Caller must FREE() */
  }
  DEBUGF (2, " %s() _tempname() failed: %s\n", __FUNCTION__, strerror(errno));
  return (NULL);
}
// For writeScanLines... we don't want to call the ExifJpegImage's
// writeScanLines at this time, since it will immediately write 
// the compressed stream directly to the file. We need to delay
// this write until the close of the image file so that the writing
// of the compressed stream is coordinated with the writing of the
// application segments. Two ways to do this. First, do the compression
// now, but have the ExifJpegImage write it to a temporary buffer, then
// we write this compressed data stream to the image file during the close.
// Second, we hold onto the reference to the ExifImageDesc passed in and
// do the compression and writing to the file during the close. Right now,
// I think the first is the best way to go...
ExifStatus 
ExifImageFile::writeScanLines( ExifImageDesc &imgDesc, exif_uint32 numLines, 
                               exif_uint32 &nextLine, exif_uint32& linesCompressed )
{ 

    // write to a temp file
    ExifStatus status = EXIF_ERROR;
    if( mTmpImageFile.size() == 0 )
    {
#ifdef _MSC_VER
 	    // Windows' _tempnam automatically uses the
	    // TMP environmental variable if it's present,
	    // otherwise it will use the "C:\\temp" directory.
	    mTmpImageFile = _tempnam("C:\\temp","oet");
        status = mOutImage.open( mTmpImageFile.c_str(), "w" ) ;
#elif (defined(__GNUC__) && (__GNUC__ > 2))
        // GCC Linkers always complain about the unsafe nature of
        // of tmpnam().  So here's a work-around. using mkstemp.
        // It's not great, but it works "safely".
        char tmpFileName[L_tmpnam];
        int len = strlen(P_tmpdir);
        strncpy(tmpFileName,P_tmpdir,len);
        strncpy(&tmpFileName[len],"/OpenExifXXXXXX",16);
        int tfd = mkstemp(tmpFileName);
        FILE * tf = fdopen(tfd,"w+");
        status = mOutImage.open(tf,tmpFileName,"w");
        mTmpImageFile = tmpFileName;
#else
        mTmpImageFile = tmpnam(NULL) ;
        status = mOutImage.open( mTmpImageFile.c_str(), "w" ) ;
#endif
    }

    if( status == EXIF_OK )
    {
        mImageModifiedOrCreated = true ;

        if( mICCProf != NULL )
        {
            mOutImage.setICCProfile(mICCProf,mICCProfSize);
            mICCProf = NULL;
        }


        status = mOutImage.writeScanLines( imgDesc, numLines,
            nextLine, linesCompressed ) ;
        mOutImage.close() ;
    }
    return status ;
}
Ejemplo n.º 18
0
static FILE* open_tmp_file(FILE** file)
{
  *file = tmpfile();
#ifdef WIN32
  if (*file == NULL)
  {
    char* tmp = getenv("TEMP");
    char* tmpFile = _tempnam(tmp, "check_");
    *file = fopen(tmpFile, "w+b");
    free(tmpFile);
  }
#endif
  return *file;
}
Ejemplo n.º 19
0
epicsShareFunc void epicsShareAPI epicsTempName ( 
	char * pNameBuf, size_t nameBufLength )
{
    if ( nameBufLength ) {
        pNameBuf[0] = '\0';
        char * pName = _tempnam ( "c:\\tmp", "epics" );
        if ( pName ) {
            if ( nameBufLength > strlen ( pName ) ) {
                strncpy ( pNameBuf, pName, nameBufLength );
            }
            free ( pName );
        }
    }
}
Ejemplo n.º 20
0
//============================================================
// Gets a new temporary filename
// buf - filename buffer
//============================================================
EXP_OPTION int getTempFileName(char* szFileName, int len)
{
    int f = 0;
    char* pFileName = 0;
    RETURN_IF_NULL_PARAM(szFileName);
    memset(szFileName, 0, len);
#ifdef WIN32
    pFileName = _tempnam(0, "ddoc");
#else
    pFileName = tempnam(0, "ddoc");
#endif
    strncpy(szFileName, pFileName, len);
    free(pFileName);
    return ERR_OK;
}
Ejemplo n.º 21
0
//-----------------------------------------------------------------------------
// Make a temporary filename
//-----------------------------------------------------------------------------
char *CScriptLib::MakeTemporaryFilename( char const *pchModPath, char *pPath, int pathSize )
{
	char *pBuffer = _tempnam( pchModPath, "mgd_" );
	if ( pBuffer[0] == '\\' )
	{
		pBuffer++;
	}
	if ( pBuffer[strlen( pBuffer )-1] == '.' )
	{
		pBuffer[strlen( pBuffer )-1] = '\0';
	}
	V_snprintf( pPath, pathSize, "%s.tmp", pBuffer );

	free( pBuffer );

	return pPath;
}
Ejemplo n.º 22
0
FILE *fmemopen (void *buf, size_t size, const char *opentype)
{
  FILE *f;
  assert(strcmp(opentype, "r") == 0);
#ifdef WIN32
  char* tmp_fname = _tempnam("%TMP%", "fmemopen");
  f = fopen(tmp_fname, "wt");
  fwrite(buf, 1, size, f);
  fclose(f);
  f = fopen(tmp_fname, "rt");
#else
  f = tmpfile();
  fwrite(buf, 1, size, f);
  rewind(f);
#endif
  return f;
}
Ejemplo n.º 23
0
string get_remote_file(const_string filename)
{
  string *lookup = NULL;
  string localname = NULL;
  boolean ret;

  if ((remote_db = hash_exists_p(hashtable_remote)) == NULL) {
    remote_db = hash_create (1007, hashtable_remote);
  }

  lookup = hash_lookup(remote_db, filename);
  /* Either the file has already been downloaded */
  if (lookup && *lookup) {
    return *lookup;
  }
  /* Or it is a new one */
  /* Get some local name */
  localname =_tempnam(getenv("TMP"), "kpse");
  if (localname == NULL) return localname;
  
  index = strlen(filename);
  log_buffer = xmalloc(index + 24);
  strcpy(log_buffer, filename);

  ret = (get_url_to_file(filename, 
			 localname,
			 0, 
			 DoDownloadLog, 
			 DoDownloadProgress,
			 NULL, /* AfxGetInstanceHandle() */
			 NetIOIE5, /*g_uiNetMethod */
			 NULL, /* _proxy_address */
			 80 /* g_uiProxyPort */
			 ) == 0);
  
  if (ret) 
    hash_insert(remote_db, filename, localname);
  else
    localname = NULL;

  puts("\n");
  free(log_buffer);
  return localname;
}
Ejemplo n.º 24
0
// TODO rename fuction and revisit
int pyi_get_temp_path(char *buffer)
{
    int i;
    char *ret;
    char prefix[16];
    stb__wchar wchar_buffer[PATH_MAX];
    stb__wchar wchar_dos83_buffer[PATH_MAX];

    // TODO later when moving to full unicode support - use 83 filename only where really necessary.
    /*
     * Get path to Windows temporary directory.
     *
     * Usually on Windows it points to a user-specific path.
     * When the username contains foreign characters then
     * the path to temp dir contains them too and the frozen
     * app fails to run.
     *
     * Converting temppath to 8.3 filename should fix this
     * when running in --onefile mode.
     */
    GetTempPathW(PATH_MAX, wchar_buffer);
    GetShortPathNameW(wchar_buffer, wchar_dos83_buffer, PATH_MAX);
    /* Convert wchar_t to utf8 just use char as usual. */
    stb_to_utf8(buffer, wchar_dos83_buffer, PATH_MAX);

    sprintf(prefix, "_MEI%d", getpid());

    /*
     * Windows does not have a race-free function to create a temporary
     * directory. Thus, we rely on _tempnam, and simply try several times
     * to avoid stupid race conditions.
     */
    for (i=0;i<5;i++) {
        // TODO use race-free fuction - if any exists?
        ret = _tempnam(buffer, prefix);
        if (mkdir(ret) == 0) {
            strcpy(buffer, ret);
            free(ret);
            return 1;
        }
        free(ret);
    }
    return 0;
}
Ejemplo n.º 25
0
void pocl_cache_mk_temp_name(char* path) {
    assert(cache_topdir_initialized);
#if defined(_MSC_VER) || defined(__MINGW32__)
    char* tmp = _tempnam(cache_topdir, "pocl_");
    assert(tmp);
    int bytes_written = snprintf(path, POCL_FILENAME_LENGTH, "%s", tmp);
    free(tmp);
    assert(bytes_written > 0 && bytes_written < POCL_FILENAME_LENGTH);
#else
    int bytes_written = snprintf(path, POCL_FILENAME_LENGTH,
             "%s/temp_XXXXXX.cl", cache_topdir);
    assert(bytes_written > 0 && bytes_written < POCL_FILENAME_LENGTH);
    /* using mkstemp() instead of tmpnam() has no real benefit
     * here, as we have to pass the filename to llvm,
     * but tmpnam() generates an annoying warning... */
    int fd = mkstemps(path, 3);
    assert(fd >= 0);
    close(fd);
#endif
}
Ejemplo n.º 26
0
static int 
lua_tmpname(lua_State *L)
{
#ifdef _WIN32
  char *tmp = _tempnam("c:/temp", "luatmp");
#else
  char *tmp = tempnam(NULL, "luatmp");
#endif
  if (tmp)
  {
    lua_pushstring(L, tmp);
    add_tmpname(L, tmp);
    free(tmp);
    return 1;
  }
  else
  {
    lua_pushnil(L);
    return 1;
  }
}
int OpenTempFile(const char* prefix)
{
  unsigned c = 0;
  std::string tname = prefix;
  tname += "_";
  tname += std::to_string(_getpid());
  tname += "_";
  while (c++ < 20) { // Loop because several threads can generate same filename.
#ifdef _WIN32
    char dir[MAX_PATH+1];
    if (!GetTempPath(sizeof(dir), dir)) { return -1; }
#else // _WIN32
    char *dir = NULL;
#endif // _WIN32
    char *name = _tempnam(dir, tname.c_str());
    if (!name) { return -1; }
#ifdef _WIN32
    HANDLE h = CreateFile(
      name,
      GENERIC_READ | GENERIC_WRITE,
      0, // No sharing
      NULL,
      CREATE_NEW,
      FILE_ATTRIBUTE_TEMPORARY | FILE_FLAG_DELETE_ON_CLOSE,
      NULL);
    free(name);
    if (h == INVALID_HANDLE_VALUE) { continue; }
    return _open_osfhandle((intptr_t)h, 0);
#else // _WIN32
    int d = _open(name, O_RDWR | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR);
    if (d < 0) { free(name); continue; }
    if (unlink(name) < 0) { free(name); _close(d); return -1; }
    free(name);
    return d;
#endif // _WIN32
  }
  return -1;
}
Ejemplo n.º 28
0
//============================================================
// Gets a new temporary filename
// buf - filename buffer
//============================================================
EXP_OPTION int getTempFileName(char* szFileName, int len)
{
	char tbuf[200];
        int f = 0;
#ifdef WIN32
	char* pFileName = 0;
#endif
	RETURN_IF_NULL_PARAM(szFileName);
	memset(szFileName, 0, len);
#ifdef WIN32
	GetTempPath(sizeof(tbuf), tbuf);
	pFileName = _tempnam(tbuf, "ddoc");
	strncpy(szFileName, pFileName, len);
	free(pFileName);
#else
	strncpy(tbuf, "/tmp/ddocXXXXXX", sizeof(tbuf));
	f = mkstemp(tbuf);
	if (f > 0) // Maybe we should use the file instead of closing it and reopening later? 
          close(f);
	strncpy(szFileName, tbuf, len);
#endif
	return ERR_OK;
}
Ejemplo n.º 29
0
void DatabaseOutputDriver::vlog(TestOutputStream stream, const char *fmt,
				va_list args)
{
  FILE *dbout = NULL;

  if (dblogFilename.empty()) {
#if defined(os_windows_test)
     char *tfile = _tempnam(".", "dts");
     if (tfile) {
        dbout = fopen(tfile, "w+b");
     }
#else
    dbout = tmpfile();
#endif
    if (NULL == dbout) {
      fprintf(stderr, "[%s:%u] - Error opening temp log file\n", __FILE__, __LINE__);
    } else { // FIXME Check return values
      int count = vfprintf(dbout, fmt, args);
      fflush(dbout);
      fseek(dbout, 0, SEEK_SET);
      char *buffer = new char[count];
      fread(buffer, sizeof (char), count, dbout);
      pretestLog.write(buffer, count);
      delete [] buffer;
      fclose(dbout);
    }
  } else {
    dbout = fopen(dblogFilename.c_str(), "a");
    if (NULL == dbout) {
      fprintf(stderr, "[%s:%u] - Error opening log file\n", __FILE__, __LINE__);
      return;
    }
    vfprintf(dbout, fmt, args);
    fclose(dbout);
  }
}
Ejemplo n.º 30
0
int getTempPath(char *buff)
{
    int i;
    char *ret;
    char prefix[16];

    GetTempPath(MAX_PATH, buff);
    sprintf(prefix, "_MEI%d", getpid());

    // Windows does not have a race-free function to create a temporary
    // directory. Thus, we rely on _tempnam, and simply try several times
    // to avoid stupid race conditions.
    for (i=0;i<5;i++) {
        ret = _tempnam(buff, prefix);
        if (mkdir(ret) == 0) {
            strcpy(buff, ret);
            strcat(buff, "\\");
            free(ret);
            return 1;
        }
        free(ret);
    }
    return 0;
}