Beispiel #1
0
static KMETHOD System_fchown(KonohaContext *kctx, KonohaStack *sfp)
{
	int fd = sfp[1].intValue;
	uid_t owner = sfp[2].intValue;
	gid_t group = sfp[3].intValue;
	int ret = fchown(fd, owner, group);
	if(ret == -1) {
		// TODO: throw
		KMakeTrace(trace, sfp);
		int fault = KLIB DiagnosisFaultType(kctx, SystemError, trace);
		KTraceErrorPoint(trace, fault, "fchown",
						LogUint("fd", fd),
						LogUint("owner", owner),
						LogUint("group", group)
			);
	}
	KReturnUnboxValue(ret == 0);
}
Beispiel #2
0
//## DIR System.opendir(String path)
static KMETHOD System_opendir(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);
	DIR *d = opendir(systemPath);
	if(d == NULL) {
		int fault = KLIB DiagnosisFaultType(kctx, kString_GuessUserFault(path)|SystemError, trace);
		KTraceErrorPoint(trace, fault, "opendir", LogText("dirname", kString_text(path)), LogErrno);
		KLIB KRuntime_raise(kctx, KException_("IO"), fault, NULL, sfp);
	}
	kDir *dir = (kDir *)KLIB new_kObject(kctx, OnStack, KGetReturnType(sfp), (uintptr_t)d);
	KFieldSet(dir, dir->PathInfoNULL, path);
	if(!PLATAPI I18NModule.isSystemCharsetUTF8(kctx)) {
		dir->readerIconv = PLATAPI I18NModule.iconvSystemCharsetToUTF8(kctx, trace);
	}
	KReturn(dir);
}
Beispiel #3
0
//## int System.open(String pathname, int flags, int mode)
static KMETHOD System_open_mode(KonohaContext *kctx, KonohaStack *sfp)
{
	kString *s = sfp[1].asString;
	const char *pathname = S_text(s);
	int flags = sfp[2].intValue;
	mode_t mode = sfp[3].intValue;
	int ret = open(pathname, flags, mode);
	if(ret == -1) {
		// TODO: throw
		KMakeTrace(trace, sfp);
		int fault = KLIB DiagnosisFaultType(kctx, kString_guessUserFault(s)|SystemError, trace);
		KTraceErrorPoint(trace, fault, "open_mode",
						LogText("pathname", pathname),
						LogUint("flags", flags),
						LogUint("mode", mode)
			);
	}
	KReturnUnboxValue(ret);
}
Beispiel #4
0
static void kFile_close(KonohaContext *kctx, kFile *file, KTraceInfo *trace)
{
	int ret = 0;
	DBG_ASSERT(file->fp != NULL);
	if(!(file->fp == stdin || file->fp == stdout || file->fp == stderr)) {
		ret = fclose(file->fp);
	}
	if(ret != 0) {
		KTraceErrorPoint(trace, SoftwareFault|SystemFault, "fclose", LogErrno);
	}
	file->fp = NULL;
	if(file->readerIconv != ICONV_NULL) {
		I18NAPI iconv_close_i(kctx, file->readerIconv);
		file->readerIconv = ICONV_NULL;
	}
	if(file->writerIconv != ICONV_NULL) {
		I18NAPI iconv_close_i(kctx, file->writerIconv);
		file->writerIconv = ICONV_NULL;
	}
}
Beispiel #5
0
//## void Curl.setOpt(int type, int data);
static KMETHOD Curl_SetOptInt(KonohaContext *kctx, KonohaStack *sfp)
{
	kCurl* kcurl = (kCurl *)sfp[0].asObject;
	CURLoption curlopt = (CURLoption)sfp[1].intValue;
	switch(curlopt) {
	case CURLOPT_BUFFERSIZE:
	case CURLOPT_CLOSEPOLICY:
	case CURLOPT_CONNECTTIMEOUT:
	case CURLOPT_DNS_CACHE_TIMEOUT:
	case CURLOPT_FTPSSLAUTH:
	case CURLOPT_HTTP_VERSION:
	case CURLOPT_HTTPAUTH:
	case CURLAUTH_ANY:
	case CURLAUTH_ANYSAFE:
	case CURLOPT_INFILESIZE:
	case CURLOPT_LOW_SPEED_LIMIT:
	case CURLOPT_LOW_SPEED_TIME:
	case CURLOPT_MAXCONNECTS:
	case CURLOPT_MAXREDIRS:
	case CURLOPT_PORT:
	case CURLOPT_PROXYAUTH:
	case CURLOPT_PROXYPORT:
	case CURLOPT_PROXYTYPE:
	case CURLOPT_RESUME_FROM:
	case CURLOPT_SSL_VERIFYHOST:
	case CURLOPT_SSLVERSION:
	case CURLOPT_TIMECONDITION:
	case CURLOPT_TIMEOUT:
	case CURLOPT_TIMEVALUE: {
		curl_easy_setopt(kcurl->curl, curlopt, sfp[2].intValue);
	}
	default: {
		KMakeTrace(trace, sfp);
		KTraceErrorPoint(trace, SoftwareFault, "curl_easy_setopt", LogWrongOption(curlopt));
		}
	}/*switch*/
	KReturnVoid();
}