Esempio n. 1
0
/**
 * g_utime:
 * @filename: a pathname in the GLib file name encoding (UTF-8 on Windows)
 * @utb: a pointer to a struct utimbuf.
 *
 * A wrapper for the POSIX utime() function. The utime() function
 * sets the access and modification timestamps of a file.
 *
 * See your C library manual for more details about how utime() works
 * on your system.
 *
 * Returns: 0 if the operation was successful, -1 if an error
 *    occurred
 *
 * Since: 2.18
 */
int
g_utime (const gchar    *filename,
         struct utimbuf *utb)
{
#ifdef G_OS_WIN32
    wchar_t *wfilename = g_utf8_to_utf16 (filename, -1, NULL, NULL, NULL);
    int retval;
    int save_errno;

    if (wfilename == NULL)
    {
        errno = EINVAL;
        return -1;
    }

    retval = _wutime (wfilename, (struct _utimbuf*) utb);
    save_errno = errno;

    g_free (wfilename);

    errno = save_errno;
    return retval;
#else
    return utime (filename, utb);
#endif
}
int wmain(int argc, wchar_t* argv[])
{
	if(argc < 3)
	{
		std::wcerr << L"Usage: " << argv[0] << L" infile delay [forced samplerate]" << std::endl;
		std::wcerr << L"Delay is in milliseconds and may be fractional." << std::endl;
		return 1;
	}

	delay = _wtof(argv[2]);
	if(delay <= 0)
	{
		std::wcerr << L"Error: Delay must be positive millisecond value, may be fractional." << std::endl;
		return 1;
	}

	if(argc >= 4)
	{
		sampleRate = _wtoi(argv[3]);
	}

	FILE *f = _wfopen(argv[1], L"rb");
	if(f == nullptr)
	{
		std::wcerr << L"Cannot open: " << argv[1] << L" for reading!" << std::endl;
		return 1;
	}

	std::wstring newFile = argv[1];
	newFile += L".tmp";
	FILE *of = _wfopen(newFile.c_str(), L"wb");
	if(of == nullptr)
	{
		std::wcerr << L"Cannot open output file: " << newFile.c_str() << L" for writing!" << std::endl;
		return 1;
	}

	if(!DecodeWAV(f, of) && !DecodeFLAC(f, of))
	{
		std::wcerr << L"Error: Unknown file type" << std::endl;
		fclose(of);
		_wremove(newFile.c_str());
		return 1;
	}

	fclose(f);
	fclose(of);

	_stat stat;
	_wstat(argv[1], &stat);
	_utimbuf timbuf;
	timbuf.actime = stat.st_atime;
	timbuf.modtime = stat.st_mtime;
	_wutime(newFile.c_str(), &timbuf);
	
	_wremove(argv[1]);
	_wrename(newFile.c_str(), argv[1]);

	return 0;
}
Esempio n. 3
0
static int rt_utime(EIF_FILENAME path, struct utimbuf *times)
{
#ifdef EIF_WINDOWS
	return _wutime(path, (struct _utimbuf *) times);
#else
	return utime(path, times);
#endif
}
/**
 *	Sets the timestamp of a file.
 *
 *	@param Filename		Full path to the file.
 *	@param Timestamp	Timestamp to set
 *	@return				File size in bytes or -1 if the file didn't exist.
 **/
UBOOL FFileManagerWindows::InternalSetFileTimestamp( const TCHAR* Filename, DOUBLE TimeStamp )
{
	_utimbuf Time;
	Time.modtime = TimeStamp;
	Time.actime = TimeStamp;

	// set it to the file
	INT ReturnCode = _wutime(Filename, &Time);

	// 0 return code was a success
	return ReturnCode == 0;
}
Esempio n. 5
0
// ---------------------------------------------------------------------------
//	Save()
//	2channel.brd形式でファイルに保存
// ---------------------------------------------------------------------------
bool
O2Boards::
Save(void)
{
	if (boards.empty())
		return false;
	
	wstring s;
	BoardsLock.Lock();
	{
		wstring category;
		s += _T("0,0\r\n");
		for (uint i = 0; i < boards.size(); i++) {
			if (category != boards[i].category) {
				category = boards[i].category;
				s += category;
				s += L"\t0\r\n";
			}
			s += L"\t";
			s += boards[i].host;
			s += L"\t";
			s += boards[i].bbsname;
			s += L"\t";
			s += boards[i].title;
			s += L"\r\n";
		}
	}
	BoardsLock.Unlock();

	string sjis;
	FromUnicode(L"shift_jis", s, sjis);

	File f;
	if (!f.open(filepath.c_str(), MODE_W))
		return false;
	f.write((void*)&sjis[0], sjis.size());
	f.close();

	struct _utimbuf times;
	times.actime  = LastModified;
	times.modtime = LastModified;

#ifdef _WIN32
	_wutime(filepath.c_str(), &times);
#else
	string tmp;
	FromUnicode(_T(DEFAULT_XML_CHARSET), filepath, tmp);
	utime(tmp.c_str(), &times);
#endif

	return true;
}
Esempio n. 6
0
int  ug_modify_file_time (const char *file_utf8, time_t mod_time)
{
	struct _utimbuf utb;
	wchar_t*        file;
	int             retval;

	utb.actime = time (NULL);
	utb.modtime = mod_time;
	file = (wchar_t*) ug_utf8_to_utf16 (file_utf8, -1, NULL);
	retval = _wutime (file, &utb);
	ug_free (file);

	return retval;
}
/**
 * Updates the modification time of the file on disk to right now, just like the unix touch command
 * @param Filename Path to the file to touch
 * @return TRUE if successful
 */
UBOOL FFileManagerWindows::InternalTouchFile(const TCHAR* Filename)
{
	time_t Now;
	// get the current time
	time(&Now);

	// use now as the time to set
	_utimbuf Time;
	Time.modtime = Now;
	Time.actime = Now;

	// set it to the file
	INT ReturnCode = _wutime(Filename, &Time);

	// 0 return code was a success
	return ReturnCode == 0;
}
Esempio n. 8
0
/* change_file_date : change the date/time of a file
    filename : the filename of the file where date/time must be modified
    dosdate : the new date at the MSDos format (4 bytes)
    tmu_date : the SAME new date at the tm_unz format */
void change_file_date(const QString& filename, uLong, tm_unz tmu_date)
{
	struct utimbuf ut;
	struct tm newdate;
	newdate.tm_sec = tmu_date.tm_sec;
	newdate.tm_min=tmu_date.tm_min;
	newdate.tm_hour=tmu_date.tm_hour;
	newdate.tm_mday=tmu_date.tm_mday;
	newdate.tm_mon=tmu_date.tm_mon;
	if (tmu_date.tm_year > 1900)
		newdate.tm_year=tmu_date.tm_year - 1900;
	else
		newdate.tm_year=tmu_date.tm_year ;
	newdate.tm_isdst=-1;

	ut.actime=ut.modtime=mktime(&newdate);
#if defined(_WIN32) && defined(HAVE_UNICODE)
	_wutime((const wchar_t*) filename.utf16(), &ut);
#else
	QByteArray fname = filename.toLocal8Bit();
	utime(fname.data(), &ut);
#endif
}