renamed set_error_on_sys_list_with_syserr to set_error_on_sys_list_with_errno in mod-sys.c
implemented getppid for win32
This commit is contained in:
		| @ -155,9 +155,10 @@ static hawk_int_t set_error_on_sys_list (hawk_rtx_t* rtx, sys_list_t* sys_list, | |||||||
| 	return ERRNUM_TO_RC(errnum); | 	return ERRNUM_TO_RC(errnum); | ||||||
| } | } | ||||||
|  |  | ||||||
| static hawk_int_t set_error_on_sys_list_with_syserr (hawk_rtx_t* rtx, sys_list_t* sys_list, const hawk_ooch_t* title) | static hawk_int_t set_error_on_sys_list_with_errno (hawk_rtx_t* rtx, sys_list_t* sys_list, const hawk_ooch_t* title) | ||||||
| { | { | ||||||
| 	int err = errno; | 	int err = errno; | ||||||
|  |  | ||||||
| 	if (title) | 	if (title) | ||||||
| 		hawk_rtx_fmttooocstr (rtx, sys_list->ctx.errmsg, HAWK_COUNTOF(sys_list->ctx.errmsg), HAWK_T("%js - %hs"), title, strerror(err)); | 		hawk_rtx_fmttooocstr (rtx, sys_list->ctx.errmsg, HAWK_COUNTOF(sys_list->ctx.errmsg), HAWK_T("%js - %hs"), title, strerror(err)); | ||||||
| 	else | 	else | ||||||
| @ -368,7 +369,7 @@ static int fnc_open (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi) | |||||||
| 		} | 		} | ||||||
| 		else | 		else | ||||||
| 		{ | 		{ | ||||||
| 			rx = set_error_on_sys_list_with_syserr(rtx, sys_list, HAWK_T("unable to open")); | 			rx = set_error_on_sys_list_with_errno(rtx, sys_list, HAWK_T("unable to open")); | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| 	else | 	else | ||||||
| @ -455,7 +456,7 @@ static int fnc_read (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi) | |||||||
| 		rx = read(sys_node->ctx.u.fd, sys_list->ctx.readbuf, reqsize); | 		rx = read(sys_node->ctx.u.fd, sys_list->ctx.readbuf, reqsize); | ||||||
| 		if (rx <= 0)  | 		if (rx <= 0)  | ||||||
| 		{ | 		{ | ||||||
| 			if (rx <= -1) rx = set_error_on_sys_list_with_syserr(rtx, sys_list, HAWK_T("unable to read")); | 			if (rx <= -1) rx = set_error_on_sys_list_with_errno(rtx, sys_list, HAWK_T("unable to read")); | ||||||
| 			goto done; | 			goto done; | ||||||
| 		} | 		} | ||||||
| 		else | 		else | ||||||
| @ -504,7 +505,7 @@ static int fnc_write (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi) | |||||||
| 		if (dptr) | 		if (dptr) | ||||||
| 		{ | 		{ | ||||||
| 			rx = write(sys_node->ctx.u.fd, dptr, dlen); | 			rx = write(sys_node->ctx.u.fd, dptr, dlen); | ||||||
| 			if (rx <= -1) rx = set_error_on_sys_list_with_syserr(rtx, sys_list, HAWK_T("unable to write")); | 			if (rx <= -1) rx = set_error_on_sys_list_with_errno(rtx, sys_list, HAWK_T("unable to write")); | ||||||
| 			hawk_rtx_freevalbcstr (rtx, a1, dptr); | 			hawk_rtx_freevalbcstr (rtx, a1, dptr); | ||||||
| 		} | 		} | ||||||
| 		else | 		else | ||||||
| @ -593,7 +594,7 @@ static int fnc_dup (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi) | |||||||
| 			} | 			} | ||||||
| 			else | 			else | ||||||
| 			{ | 			{ | ||||||
| 				rx = set_error_on_sys_list_with_syserr(rtx, sys_list, HAWK_NULL); | 				rx = set_error_on_sys_list_with_errno(rtx, sys_list, HAWK_NULL); | ||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
| 		else | 		else | ||||||
| @ -616,7 +617,7 @@ static int fnc_dup (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi) | |||||||
| 			} | 			} | ||||||
| 			else | 			else | ||||||
| 			{ | 			{ | ||||||
| 				rx = set_error_on_sys_list_with_syserr(rtx, sys_list, HAWK_NULL); | 				rx = set_error_on_sys_list_with_errno(rtx, sys_list, HAWK_NULL); | ||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| @ -798,7 +799,7 @@ static int fnc_pipe (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi) | |||||||
| 	} | 	} | ||||||
| 	else | 	else | ||||||
| 	{ | 	{ | ||||||
| 		rx = set_error_on_sys_list_with_syserr(rtx, sys_list, HAWK_NULL); | 		rx = set_error_on_sys_list_with_errno(rtx, sys_list, HAWK_NULL); | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	hawk_rtx_setretval (rtx, hawk_rtx_makeintval(rtx, rx)); | 	hawk_rtx_setretval (rtx, hawk_rtx_makeintval(rtx, rx)); | ||||||
| @ -1001,7 +1002,7 @@ static int fnc_fork (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi) | |||||||
| 	rx = set_error_on_sys_list(rtx, sys_list, HAWK_ENOIMPL, HAWK_NULL); | 	rx = set_error_on_sys_list(rtx, sys_list, HAWK_ENOIMPL, HAWK_NULL); | ||||||
| #else | #else | ||||||
| 	rx = fork(); | 	rx = fork(); | ||||||
| 	if (rx <= -1) rx = set_error_on_sys_list_with_syserr(rtx, sys_list, HAWK_NULL); | 	if (rx <= -1) rx = set_error_on_sys_list_with_errno(rtx, sys_list, HAWK_NULL); | ||||||
| #endif | #endif | ||||||
|  |  | ||||||
| 	retv = hawk_rtx_makeintval(rtx, rx); | 	retv = hawk_rtx_makeintval(rtx, rx); | ||||||
| @ -1045,7 +1046,7 @@ static int fnc_wait (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi) | |||||||
| 	status = 0; | 	status = 0; | ||||||
| #else | #else | ||||||
| 	rx = waitpid(pid, &status, opts); | 	rx = waitpid(pid, &status, opts); | ||||||
| 	if (rx <= -1) rx = set_error_on_sys_list_with_syserr(rtx, sys_list, HAWK_NULL); | 	if (rx <= -1) rx = set_error_on_sys_list_with_errno(rtx, sys_list, HAWK_NULL); | ||||||
| #endif | #endif | ||||||
|  |  | ||||||
| done: | done: | ||||||
| @ -1154,7 +1155,7 @@ static int fnc_kill (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi) | |||||||
| 		rx = set_error_on_sys_list(rtx, sys_list, HAWK_ENOIMPL, HAWK_NULL); | 		rx = set_error_on_sys_list(rtx, sys_list, HAWK_ENOIMPL, HAWK_NULL); | ||||||
| #else | #else | ||||||
| 		rx = kill(pid, sig); | 		rx = kill(pid, sig); | ||||||
| 		if (rx <= -1) rx = set_error_on_sys_list_with_syserr(rtx, sys_list, HAWK_NULL); | 		if (rx <= -1) rx = set_error_on_sys_list_with_errno(rtx, sys_list, HAWK_NULL); | ||||||
| #endif | #endif | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| @ -1184,10 +1185,10 @@ static int fnc_getpgid (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi) | |||||||
| 	/* TODO: support specifing calling process id other than 0 */ | 	/* TODO: support specifing calling process id other than 0 */ | ||||||
| 	#if defined(HAVE_GETPGID) | 	#if defined(HAVE_GETPGID) | ||||||
| 	rx = getpgid(0); | 	rx = getpgid(0); | ||||||
| 	if (rx <= -1) rx = set_error_on_sys_list_with_syserr(rtx, sys_list, HAWK_NULL); | 	if (rx <= -1) rx = set_error_on_sys_list_with_errno(rtx, sys_list, HAWK_NULL); | ||||||
| 	#elif defined(HAVE_GETPGRP) | 	#elif defined(HAVE_GETPGRP) | ||||||
| 	rx = getpgrp(); | 	rx = getpgrp(); | ||||||
| 	if (rx <= -1) rx = set_error_on_sys_list_with_syserr(rtx, sys_list, HAWK_NULL); | 	if (rx <= -1) rx = set_error_on_sys_list_with_errno(rtx, sys_list, HAWK_NULL); | ||||||
| 	#else | 	#else | ||||||
| 	rx = set_error_on_sys_list(rtx, sys_list, HAWK_ENOIMPL, HAWK_NULL); | 	rx = set_error_on_sys_list(rtx, sys_list, HAWK_ENOIMPL, HAWK_NULL); | ||||||
| 	#endif | 	#endif | ||||||
| @ -1243,19 +1244,28 @@ static int fnc_getpid (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi) | |||||||
|  |  | ||||||
| static int fnc_gettid (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi) | static int fnc_gettid (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi) | ||||||
| { | { | ||||||
| 	hawk_intptr_t pid; | 	hawk_intptr_t rx; | ||||||
| 	hawk_val_t* retv; | 	hawk_val_t* retv; | ||||||
| 	sys_list_t* sys_list = rtx_to_sys_list(rtx, fi); | 	sys_list_t* sys_list = rtx_to_sys_list(rtx, fi); | ||||||
|  |  | ||||||
| #if defined(_WIN32) | #if defined(_WIN32) | ||||||
| 	pid = GetCurrentThreadId(); | 	rx = GetCurrentThreadId(); | ||||||
| 	 | 	/* never fails */ | ||||||
| #elif defined(__OS2__) | #elif defined(__OS2__) | ||||||
| 	PTIB tib; | 	PTIB tib; | ||||||
| 	PPIB pib; | 	PPIB pib; | ||||||
|  | 	APIRET rc; | ||||||
|  |  | ||||||
| 	pid = (DosGetInfoBlocks (&tib, &pib) == NO_ERROR && tib->tib_ptib2)? | 	rc = DosGetInfoBlocks(&tib, &pib); | ||||||
| 		 tib->tib_ptib2->tib2_ultid: -1; | 	if (rc == NO_ERROR) | ||||||
|  | 	{ | ||||||
|  | 		if (tib->tib_ptib2) rx = tib->tib_ptib2->tib2_ultid; | ||||||
|  | 		else rx = set_error_on_sys_list(rtx, sys_list, HAWK_ESYSERR, HAWK_NULL); | ||||||
|  | 	} | ||||||
|  | 	else | ||||||
|  | 	{ | ||||||
|  | 		rx = set_error_on_sys_list(rtx, sys_list, hawk_syserr_to_errnum(rc), HAWK_NULL); | ||||||
|  | 	} | ||||||
|  |  | ||||||
| #elif defined(__DOS__) | #elif defined(__DOS__) | ||||||
| 	/* TOOD: implement this*/ | 	/* TOOD: implement this*/ | ||||||
| @ -1263,15 +1273,15 @@ static int fnc_gettid (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi) | |||||||
|  |  | ||||||
| #else | #else | ||||||
| 	#if defined(SYS_gettid) && defined(HAWK_SYSCALL0) | 	#if defined(SYS_gettid) && defined(HAWK_SYSCALL0) | ||||||
| 	HAWK_SYSCALL0 (pid, SYS_gettid); | 	HAWK_SYSCALL0 (rx, SYS_gettid); | ||||||
| 	#elif defined(SYS_gettid) | 	#elif defined(SYS_gettid) | ||||||
| 	pid = syscall(SYS_gettid); | 	rx = syscall(SYS_gettid); | ||||||
| 	#else | 	#else | ||||||
| 	rx = set_error_on_sys_list(rtx, sys_list, HAWK_ENOIMPL, HAWK_NULL); | 	rx = set_error_on_sys_list(rtx, sys_list, HAWK_ENOIMPL, HAWK_NULL); | ||||||
| 	#endif | 	#endif | ||||||
| #endif | #endif | ||||||
|  |  | ||||||
| 	retv = hawk_rtx_makeintval(rtx, (hawk_int_t)pid); | 	retv = hawk_rtx_makeintval(rtx, rx); | ||||||
| 	if (retv == HAWK_NULL) return -1; | 	if (retv == HAWK_NULL) return -1; | ||||||
|  |  | ||||||
| 	hawk_rtx_setretval (rtx, retv); | 	hawk_rtx_setretval (rtx, retv); | ||||||
| @ -1285,8 +1295,36 @@ static int fnc_getppid (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi) | |||||||
| 	sys_list_t* sys_list = rtx_to_sys_list(rtx, fi); | 	sys_list_t* sys_list = rtx_to_sys_list(rtx, fi); | ||||||
|  |  | ||||||
| #if defined(_WIN32) | #if defined(_WIN32) | ||||||
| 	/* TOOD: implement this*/ | 	DWORD pid; | ||||||
| 	rx = set_error_on_sys_list(rtx, sys_list, HAWK_ENOIMPL, HAWK_NULL); | 	HANDLE ps; | ||||||
|  | 	PROCESSENTRY32 p; | ||||||
|  |  | ||||||
|  | 	pid = GetCurrentPorcessId(); | ||||||
|  | 	ps = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); | ||||||
|  | 	if (ps == INVALID_HANDLE_VALUE) | ||||||
|  | 	{ | ||||||
|  | 		rx = set_error_on_sys_list(rtx, sys_list, hawk_syserr_to_errnum(GetLastError()), HAWK_NULL); | ||||||
|  | 	} | ||||||
|  | 	else | ||||||
|  | 	{ | ||||||
|  | 		rx = set_error_on_sys_list(rtx, sys_list, HAWK_ENOENT, HAWK_NULL); | ||||||
|  |  | ||||||
|  | 		p.dwSize = HAWK_SZIEOF(p); | ||||||
|  | 		if (Process32First(ps, &p)) | ||||||
|  | 		{ | ||||||
|  | 			do | ||||||
|  | 			{ | ||||||
|  | 				if (p.th32ProcessID == pid) | ||||||
|  | 				{ | ||||||
|  | 					rx = p.th32ParentProcessID; /* got it */ | ||||||
|  | 					break; | ||||||
|  | 				} | ||||||
|  | 			} | ||||||
|  | 			while (Process32Next(ps, &p)); | ||||||
|  | 		} | ||||||
|  |  | ||||||
|  | 		CloseHandle (ps); | ||||||
|  | 	} | ||||||
|  |  | ||||||
| #elif defined(__OS2__) | #elif defined(__OS2__) | ||||||
| 	/* TOOD: implement this*/ | 	/* TOOD: implement this*/ | ||||||
| @ -2416,7 +2454,7 @@ static int fnc_writelog (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi) | |||||||
| 		#endif | 		#endif | ||||||
| 			if (!tmx)  | 			if (!tmx)  | ||||||
| 			{ | 			{ | ||||||
| 				rx = set_error_on_sys_list_with_syserr(rtx, sys_list, HAWK_T("unable to get local time")); | 				rx = set_error_on_sys_list_with_errno(rtx, sys_list, HAWK_T("unable to get local time")); | ||||||
| 				goto done; | 				goto done; | ||||||
| 			} | 			} | ||||||
|  |  | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user