コード例 #1
0
ファイル: path_glue.c プロジェクト: Kouhei-Moriya/konoha3
//## boolean System.mkdir(String path, int mode)
static KMETHOD System_mkdir(KonohaContext *kctx, KonohaStack *sfp)
{
	KMakeTrace(trace, sfp);
	char buffer[K_PATHMAX];
	kString *path = sfp[1].asString;
	const char *systemPath = PLATAPI I18NModule.formatSystemPath(kctx, buffer, sizeof(buffer), kString_text(path), kString_size(path), trace);
	mode_t mode = (mode_t)sfp[2].intValue;
	int ret = mkdir(systemPath, mode);
	if(ret == -1) {
		KTraceErrorPoint(trace, SystemFault, "mkdir", LogFileName(kString_text(path)), LogMode(mode), LogErrno);
	}
	else {
		KTraceChangeSystemPoint(trace, "mkdir", LogFileName(kString_text(path)), LogMode(mode));
	}
	KReturnUnboxValue(ret != -1);
}
コード例 #2
0
ファイル: path_glue.c プロジェクト: Kouhei-Moriya/konoha3
//## boolean System.rmdir(String path)
static KMETHOD System_rmdir(KonohaContext *kctx, KonohaStack *sfp)
{
	KMakeTrace(trace, sfp);
	char buffer[K_PATHMAX];
	kString *path = sfp[1].asString;
	const char *systemPath = PLATAPI I18NModule.formatSystemPath(kctx, buffer, sizeof(buffer), kString_text(path), kString_size(path), trace);
	int ret = rmdir(systemPath);
	if(ret == -1) {
		int fault = KLIB DiagnosisFaultType(kctx, kString_GuessUserFault(path)|SystemError, trace);
		KTraceErrorPoint(trace, fault, "rmdir", LogFileName(kString_text(path)), LogErrno);
	}
	else {
		KTraceChangeSystemPoint(trace, "rmdir", LogFileName(kString_text(path)));
	}
	KReturnUnboxValue(ret != -1);
}
コード例 #3
0
ファイル: File_glue.c プロジェクト: imasahiro/konoha3
//## FILE FILE.new(String path, String mode);
static KMETHOD File_new(KonohaContext *kctx, KonohaStack *sfp)
{
	KMakeTrace(trace, sfp);
	char buffer[K_PATHMAX];
	kString *path = sfp[1].asString;
	const char *systemPath = I18NAPI formatSystemPath(kctx, buffer, sizeof(buffer), kString_text(path), kString_size(path), trace);
	const char *mode = kString_text(sfp[2].asString);
	FILE *fp = fopen(systemPath, mode);
	kFile *file = (kFile *) sfp[0].asObject;
	if(fp == NULL) {
		int fault = KLIB DiagnosisFaultType(kctx, kString_GuessUserFault(path)|SystemError, trace);
		KTraceErrorPoint(trace, fault, "fopen",
			LogText("filename", kString_text(path)), LogText("mode", mode), LogErrno);
		KLIB KRuntime_raise(kctx, KException_("IO"), fault, NULL, sfp);
	}
	if(mode[0] == 'w' || mode[0] == 'a' || mode[1] == '+') {
		KTraceChangeSystemPoint(trace, "fopen", LogFileName(kString_text(path)), LogText("mode", mode));
	}
	file->fp = fp;
	KFieldInit(file, file->PathInfoNULL, path);
	if(!I18NAPI isSystemCharsetUTF8(kctx)) {
		if(mode[0] == 'w' || mode[0] == 'a' || mode[1] == '+') {
			file->writerIconv = I18NAPI iconvUTF8ToSystemCharset(kctx, trace);
		}
		else {
			file->readerIconv = I18NAPI iconvSystemCharsetToUTF8(kctx, trace);
		}
	}
	KReturn(file);
}
コード例 #4
0
ファイル: path_glue.c プロジェクト: Kouhei-Moriya/konoha3
static KMETHOD System_symlink(KonohaContext *kctx, KonohaStack *sfp)
{
	char buffer[K_PATHMAX], buffer2[K_PATHMAX];
	kString *path = sfp[1].asString, *path2 = sfp[2].asString;
	KMakeTrace(trace, sfp);
	const char *oldpath = PLATAPI I18NModule.formatSystemPath(kctx, buffer, sizeof(buffer), kString_text(path), kString_size(path), trace);
	const char *newpath = PLATAPI I18NModule.formatSystemPath(kctx, buffer2, sizeof(buffer2), kString_text(path2), kString_size(path2), trace);
	int ret = symlink(oldpath, newpath);
	if(ret == -1) {
		int fault = KLIB DiagnosisFaultType(kctx, kString_GuessUserFault(path)|kString_GuessUserFault(path2)|SystemError, trace);
		KTraceErrorPoint(trace, fault, "symlink", LogFileName(kString_text(path)), LogFileName2(kString_text(path2)), LogErrno);
	}
	else {
		KTraceChangeSystemPoint(trace, "symlink", LogFileName(kString_text(path)), LogFileName2(kString_text(path2)), LogErrno);
	}
	KReturnUnboxValue(ret != -1);
}
コード例 #5
0
ファイル: path_glue.c プロジェクト: doly/minikonoha
//## boolean System.truncate(String path, int length)
static KMETHOD System_truncate(KonohaContext *kctx, KonohaStack *sfp)
{
	KMakeTrace(trace, sfp);
	char buffer[K_PATHMAX];
	kString *path = sfp[1].asString;
	const char *systemPath = PLATAPI formatSystemPath(kctx, buffer, sizeof(buffer), S_text(path), S_size(path), trace);
	off_t length = (off_t)sfp[2].intValue;
	int ret = truncate(systemPath, length);
	if(ret == -1) {
		int fault = KLIB DiagnosisFaultType(kctx, kString_guessUserFault(path)|SystemError, trace);
		KTraceErrorPoint(trace, fault, "truncate", LogFileName(S_text(path)), LogUint("length", length), LogErrno);
	}
	else {
		KTraceChangeSystemPoint(trace, "truncate", LogFileName(S_text(path)), LogUint("length", length));
	}
	KReturnUnboxValue(ret != -1);
}
コード例 #6
0
ファイル: logfile.c プロジェクト: MalaGaM/nxscripts
VOID SCALL LogFileTraceV(const CHAR *file, const CHAR *func, INT line, const CHAR *format, va_list argList)
{
#if 0
    CHAR        location[MAX_PATH];
#endif
    CHAR        *messageEnd;
    DWORD       errorCode;
    DWORD       processId;
    DWORD       threadId;
    LOG_ENTRY   *entry;
    size_t      remaining;

    // Preserve system error code
    errorCode = GetLastError();

    ASSERT(file != NULL);
    ASSERT(func != NULL);
    ASSERT(format != NULL);

    processId = GetCurrentProcessId();
    threadId  = GetCurrentThreadId();

    // Retrieve a spare entry structure (also checks log status)
    entry = GetSpareEntry();
    if (entry != NULL) {
        //
        // Available trace information:
        //
        // file      - Source file
        // func      - Function name in the source file
        // line      - Line number in the source file
        // processId - Current process ID
        // threadId  - Current thread ID
        //
        GetLocalTime(&entry->time);

#if 0
        StringCchPrintfA(location, ELEMENT_COUNT(location), "%s:%d", LogFileName(file), line);

        StringCchPrintfExA(entry->message, ELEMENT_COUNT(entry->message),
            &messageEnd, &remaining, 0, "%-20s - %-20s - ", location, func);
#else
        StringCchPrintfExA(entry->message, ELEMENT_COUNT(entry->message),
            &messageEnd, &remaining, 0, "%s - ", func);
#endif
        StringCchVPrintfExA(messageEnd, remaining, NULL, &remaining, 0, format, argList);

        entry->length = ELEMENT_COUNT(entry->message) - remaining;

        // Insert log entry into the write queue
        QueueInsert(entry);
    }

    // Restore system error code
    SetLastError(errorCode);
}
コード例 #7
0
ファイル: path_glue.c プロジェクト: Kouhei-Moriya/konoha3
//## boolean chroot(String path)
static KMETHOD System_chroot(KonohaContext *kctx, KonohaStack *sfp)
{
	KMakeTrace(trace, sfp);
	char buffer[K_PATHMAX];
	kString *path = sfp[1].asString;
	const char *systemPath = PLATAPI I18NModule.formatSystemPath(kctx, buffer, sizeof(buffer), kString_text(path), kString_size(path), trace);
	int ret = chroot(systemPath);
	if(ret == -1) {
		KTraceErrorPoint(trace, SystemFault, "chroot", LogFileName(kString_text(path)), LogErrno);
	}
	KReturnUnboxValue(ret != -1);
}
コード例 #8
0
ファイル: path_glue.c プロジェクト: doly/minikonoha
// boolean System.access(String path, int mode);
static KMETHOD System_access(KonohaContext *kctx, KonohaStack *sfp)
{
	KMakeTrace(trace, sfp);
	char buffer[K_PATHMAX];
	kString *path = sfp[1].asString;
	const char *systemPath = PLATAPI formatSystemPath(kctx, buffer, sizeof(buffer), S_text(path), S_size(path), trace);
	mode_t mode = (mode_t)sfp[2].intValue;
	int ret = access(systemPath, mode);
	if(ret == -1) {
		KTraceErrorPoint(trace, SystemFault, "access", LogFileName(S_text(path)), LogMode(mode), LogErrno);
	}
	KReturnUnboxValue(ret != -1);
}
コード例 #9
0
ファイル: path_glue.c プロジェクト: Kouhei-Moriya/konoha3
static KMETHOD System_lchown(KonohaContext *kctx, KonohaStack *sfp)
{
	KMakeTrace(trace, sfp);
	char buffer[K_PATHMAX];
	kString *path = sfp[1].asString;
	const char *systemPath = PLATAPI I18NModule.formatSystemPath(kctx, buffer, sizeof(buffer), kString_text(path), kString_size(path), trace);
	uid_t owner = (uid_t)sfp[2].intValue;
	gid_t group = (gid_t)sfp[3].intValue;
	int ret = lchown(systemPath, owner, group);
	if(ret == -1) {
		KTraceErrorPoint(trace, SystemFault, "lchown", LogFileName(kString_text(path)), LogOwner(owner), LogGroup(group), LogErrno);
	}
	KReturnUnboxValue(ret != -1);
}
コード例 #10
0
ファイル: path_glue.c プロジェクト: Kouhei-Moriya/konoha3
//## String System.realpath(String path)
static KMETHOD System_realpath(KonohaContext *kctx, KonohaStack *sfp)
{
	KMakeTrace(trace, sfp);
	char buffer[K_PATHMAX], filepath[K_PATHMAX] = {0};
	kString *path = sfp[1].asString;
	const char *systemPath = PLATAPI I18NModule.formatSystemPath(kctx, buffer, sizeof(buffer), kString_text(path), kString_size(path), trace);
	char *cwd = realpath(systemPath, filepath);
	if(cwd != NULL) {
		const char *konohaPath = PLATAPI I18NModule.formatKonohaPath(kctx, buffer, sizeof(buffer), cwd, strlen(cwd), trace);
		KReturn(KLIB new_kString(kctx, OnStack, konohaPath, strlen(konohaPath), 0));
	}
	else {
		KTraceErrorPoint(trace, SystemFault, "realpath", LogFileName(kString_text(path)), LogErrno);
		KReturn(KNULL(String));
	}
}
コード例 #11
0
ファイル: FwGrEngine.cpp プロジェクト: bbriggs/FieldWorks
/*----------------------------------------------------------------------------------------------
	Generate the name of the file where the log will be written. It goes in the directory
	defined by either the TEMP or TMP environment variable.
----------------------------------------------------------------------------------------------*/
std::ofstream * FwGrEngine::CreateLogFile(std::ofstream & strmLog, bool fAppend)
{
	if (!m_fLog)
		return NULL;

	std::string staFile;
	if (!LogFileName(staFile))
		return NULL; // can't figure out where to put the log file

	if (fAppend)
		strmLog.open(staFile.c_str(), std::ios::app);	// append
	else
		strmLog.open(staFile.c_str());

	return &strmLog;
}
コード例 #12
0
ファイル: path_glue.c プロジェクト: Kouhei-Moriya/konoha3
static KMETHOD System_readlink(KonohaContext *kctx, KonohaStack *sfp)
{
	KMakeTrace(trace, sfp);
	char buffer[K_PATHMAX];
	kString *path = sfp[1].asString;
	const char *systemPath = PLATAPI I18NModule.formatSystemPath(kctx, buffer, sizeof(buffer), kString_text(path), kString_size(path), trace);
	char pathbuf[K_PATHMAX];
	ssize_t ret = readlink(systemPath, pathbuf, K_PATHMAX);
	if(ret == -1) {
		int fault = KLIB DiagnosisFaultType(kctx, kString_GuessUserFault(path)|SystemError, trace);
		KTraceErrorPoint(trace, fault, "readlink", LogFileName(kString_text(path)), LogErrno);
		KReturn(KNULL(String));
	}
	else {
		const char *konohaPath = PLATAPI I18NModule.formatKonohaPath(kctx, buffer, sizeof(buffer), pathbuf, strlen(pathbuf), trace);
		KReturn(KLIB new_kString(kctx, OnStack, konohaPath, strlen(konohaPath), 0));
	}
}
コード例 #13
0
void Start_Recompiler_Log (void)
{
    CPath LogFileName(g_Settings->LoadStringVal(Directory_Log).c_str(), "CPUoutput.log");
    if (g_CPULogFile != NULL)
    {
        Stop_Recompiler_Log();
    }
    g_CPULogFile = new CLog();
    if (g_CPULogFile)
    {
        if (g_CPULogFile->Open(LogFileName))
        {
            g_CPULogFile->SetMaxFileSize(300 * CLog::MB);
            g_bRecompilerLogging = true;
        }
        else
        {
            delete g_CPULogFile;
            g_CPULogFile = NULL;
        }
    }
}