/* Generated by Nim Compiler v2.2.10 */
/* Compiled for: MacOSX, arm64, clang */
/* Command for C compiler:
   clang -c  -w -ferror-limit=3 -fno-strict-aliasing -pthread -isysroot /Applications/Xcode_16.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk -target arm64-apple-darwin24.2.0 -O3   -I/Users/runner/work/nightlies/nightlies/nim-2.2.10/lib -I/Users/runner/work/nightlies/nightlies/nim-2.2.10/dist/atlas/src -o /Users/runner/work/nightlies/nightlies/nim-2.2.10/dist/atlas/.nimcache/@pstd@sprivate@soscommon.nim.c.o /Users/runner/work/nightlies/nightlies/nim-2.2.10/dist/atlas/.nimcache/@pstd@sprivate@soscommon.nim.c */
#define NIM_INTBITS 64
#define NIM_EmulateOverflowChecks

#include "nimbase.h"
#include <sys/stat.h>
#include <sys/types.h>
#include <time.h>
#include <string.h>
#include <stdio.h>
#include <errno.h>
#undef LANGUAGE_C
#undef MIPSEB
#undef MIPSEL
#undef PPC
#undef R3000
#undef R4000
#undef i386
#undef linux
#undef mips
#undef near
#undef far
#undef powerpc
#undef unix
typedef struct NimStrPayload NimStrPayload;
typedef struct NimStringV2 NimStringV2;
typedef struct tyTuple__4ZA8Mtd29a9cAR3xLlz7LVrw tyTuple__4ZA8Mtd29a9cAR3xLlz7LVrw;
typedef struct tyTuple__UV3llMMYFckfui8YMBuUZA tyTuple__UV3llMMYFckfui8YMBuUZA;
struct NimStrPayload {
	NI cap;
	NIM_CHAR data[SEQ_DECL_SIZE];
};
struct NimStringV2 {
	NI len;
	NimStrPayload* p;
};
typedef NU8 tyEnum_PathComponent__OiWviOlsjyqprC56d9bn9b4Q;
struct tyTuple__4ZA8Mtd29a9cAR3xLlz7LVrw {
	tyEnum_PathComponent__OiWviOlsjyqprC56d9bn9b4Q Field0;
	NIM_BOOL Field1;
};
struct tyTuple__UV3llMMYFckfui8YMBuUZA {
	NimStringV2 Field0;
	NimStringV2 Field1;
};
static N_INLINE(void, nimZeroMem)(void* p_p0, NI size_p1);
static N_INLINE(void, nimSetMem__system_u2188)(void* a_p0, int v_p1, NI size_p2);
static N_INLINE(NCSTRING, nimToCStringConv)(NimStringV2 s_p0);
N_LIB_PRIVATE N_NIMCALL(void, failedAssertImpl__stdZassertions_u95)(NimStringV2 msg_p0);
static N_INLINE(NIM_BOOL*, nimErrorFlag)(void);
N_LIB_PRIVATE N_NIMCALL(NI32, osLastError__stdZoserrors_u122)(void);
N_LIB_PRIVATE N_NOINLINE(void, raiseOSError__stdZoserrors_u119)(NI32 errorCode_p0, NimStringV2 additionalInfo_p1);
N_LIB_PRIVATE N_NIMCALL(NimStringV2, dollar___stdZprivateZoscommon_u93)(tyTuple__UV3llMMYFckfui8YMBuUZA* x_p0);
N_LIB_PRIVATE N_NOCONV(void, deallocShared)(void* p_p0);
static const struct {
  NI cap; NIM_CHAR data[34+1];
} TM__ZrvRRRmaDcxlFjSFGlhGzQ_2 = { 34 | NIM_STRLIT_FLAG, "oscommon.nim(76, 13) `path != \"\"` " };
static const NimStringV2 TM__ZrvRRRmaDcxlFjSFGlhGzQ_3 = {34, (NimStrPayload*)&TM__ZrvRRRmaDcxlFjSFGlhGzQ_2};
extern NIM_THREADVAR NIM_BOOL nimInErrorMode__system_u4198;
static N_INLINE(void, nimSetMem__system_u2188)(void* a_p0, int v_p1, NI size_p2) {
	void* T1_;
	T1_ = (void*)0;
	T1_ = memset(a_p0, v_p1, ((size_t) (size_p2)));
}
static N_INLINE(void, nimZeroMem)(void* p_p0, NI size_p1) {
	nimSetMem__system_u2188(p_p0, ((int)0), size_p1);
}
static N_INLINE(NCSTRING, nimToCStringConv)(NimStringV2 s_p0) {
	NCSTRING result;
	{
		if (!(s_p0.len == ((NI)0))) goto LA3_;
		result = "";
	}
	goto LA1_;
LA3_: ;
	{
		result = ((NCSTRING) ((*s_p0.p).data));
	}
LA1_: ;
	return result;
}
N_LIB_PRIVATE N_NIMCALL(NIM_BOOL, nosdirExists)(NimStringV2 dir_p0) {
	NIM_BOOL result;
	struct stat res_1;
	NIM_BOOL T1_;
	int T2_;
	nimZeroMem((void*)(&res_1), sizeof(struct stat));
	T1_ = (NIM_BOOL)0;
	T2_ = (int)0;
	T2_ = stat(nimToCStringConv(dir_p0), (&res_1));
	T1_ = (((NI32)0) <= T2_);
	if (!(T1_)) goto LA3_;
	T1_ = S_ISDIR(res_1.st_mode);
LA3_: ;
	result = T1_;
	return result;
}
N_LIB_PRIVATE N_NIMCALL(NIM_BOOL, nosfileExists)(NimStringV2 filename_p0) {
	NIM_BOOL result;
	struct stat res_1;
	NIM_BOOL T1_;
	int T2_;
{	nimZeroMem((void*)(&res_1), sizeof(struct stat));
	T1_ = (NIM_BOOL)0;
	T2_ = (int)0;
	T2_ = stat(nimToCStringConv(filename_p0), (&res_1));
	T1_ = (((NI32)0) <= T2_);
	if (!(T1_)) goto LA3_;
	T1_ = S_ISREG(res_1.st_mode);
LA3_: ;
	result = T1_;
	goto BeforeRet_;
	}BeforeRet_: ;
	return result;
}
static N_INLINE(NIM_BOOL*, nimErrorFlag)(void) {
	NIM_BOOL* result;
	result = (&nimInErrorMode__system_u4198);
	return result;
}
N_LIB_PRIVATE N_NIMCALL(tyTuple__4ZA8Mtd29a9cAR3xLlz7LVrw, getSymlinkFileKind__stdZprivateZoscommon_u17)(NimStringV2 path_p0) {
	tyTuple__4ZA8Mtd29a9cAR3xLlz7LVrw result;
	struct stat s_1;
	tyEnum_PathComponent__OiWviOlsjyqprC56d9bn9b4Q colontmp_;
	NIM_BOOL colontmp__2;
NIM_BOOL* nimErr_;
{nimErr_ = nimErrorFlag();
	nimZeroMem((void*)(&result), sizeof(tyTuple__4ZA8Mtd29a9cAR3xLlz7LVrw));
	nimZeroMem((void*)(&s_1), sizeof(struct stat));
	{
		if (!!(!((path_p0.len == 0)))) goto LA3_;
		failedAssertImpl__stdZassertions_u95(TM__ZrvRRRmaDcxlFjSFGlhGzQ_3);
		if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
	}
LA3_: ;
	colontmp_ = ((tyEnum_PathComponent__OiWviOlsjyqprC56d9bn9b4Q)1);
	colontmp__2 = NIM_FALSE;
	result.Field0 = colontmp_;
	result.Field1 = colontmp__2;
	{
		int T7_;
		T7_ = (int)0;
		T7_ = stat(nimToCStringConv(path_p0), (&s_1));
		if (!(T7_ == ((NI32)0))) goto LA8_;
		{
			NIM_BOOL T12_;
			tyEnum_PathComponent__OiWviOlsjyqprC56d9bn9b4Q colontmp__3;
			NIM_BOOL colontmp__4;
			T12_ = (NIM_BOOL)0;
			T12_ = S_ISDIR(s_1.st_mode);
			if (!T12_) goto LA13_;
			colontmp__3 = ((tyEnum_PathComponent__OiWviOlsjyqprC56d9bn9b4Q)3);
			colontmp__4 = NIM_FALSE;
			result.Field0 = colontmp__3;
			result.Field1 = colontmp__4;
		}
		goto LA10_;
LA13_: ;
		{
			NIM_BOOL T16_;
			tyEnum_PathComponent__OiWviOlsjyqprC56d9bn9b4Q colontmp__5;
			NIM_BOOL colontmp__6;
			T16_ = (NIM_BOOL)0;
			T16_ = S_ISREG(s_1.st_mode);
			if (!!(T16_)) goto LA17_;
			colontmp__5 = ((tyEnum_PathComponent__OiWviOlsjyqprC56d9bn9b4Q)1);
			colontmp__6 = NIM_TRUE;
			result.Field0 = colontmp__5;
			result.Field1 = colontmp__6;
		}
		goto LA10_;
LA17_: ;
LA10_: ;
	}
LA8_: ;
	}BeforeRet_: ;
	return result;
}
N_LIB_PRIVATE N_NIMCALL(NIM_BOOL, tryMoveFSObject__stdZprivateZoscommon_u86)(NimStringV2 source_p0, NimStringV2 dest_p1, NIM_BOOL isDir_p2) {
	NIM_BOOL result;
	int T1_;
NIM_BOOL* nimErr_;
{nimErr_ = nimErrorFlag();
	T1_ = (int)0;
	T1_ = rename(nimToCStringConv(source_p0), nimToCStringConv(dest_p1));
	result = (T1_ == ((NI32)0));
	{
		NI32 err_1;
		NIM_BOOL isAccessDeniedError_1;
		if (!!(result)) goto LA4_;
		err_1 = osLastError__stdZoserrors_u122();
		if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
		isAccessDeniedError_1 = (err_1 == ((NI32) (EXDEV)));
		{
			NimStringV2 colontmpD_;
			tyTuple__UV3llMMYFckfui8YMBuUZA T11_;
			if (!!(isAccessDeniedError_1)) goto LA8_;
			colontmpD_.len = 0; colontmpD_.p = NIM_NIL;
			T11_.Field0 = source_p0;
			T11_.Field1 = dest_p1;
			colontmpD_ = dollar___stdZprivateZoscommon_u93((&T11_));
			if (NIM_UNLIKELY(*nimErr_)) goto LA10_;
			raiseOSError__stdZoserrors_u119(err_1, colontmpD_);
			if (NIM_UNLIKELY(*nimErr_)) goto LA10_;
			{
				LA10_:;
			}
			{
				if (colontmpD_.p && !(colontmpD_.p->cap & NIM_STRLIT_FLAG)) {
 deallocShared(colontmpD_.p);
}
			}
			if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
		}
LA8_: ;
	}
LA4_: ;
	}BeforeRet_: ;
	return result;
}
N_LIB_PRIVATE N_NIMCALL(NIM_BOOL, nossymlinkExists)(NimStringV2 link_p0) {
	NIM_BOOL result;
	struct stat res_1;
	NIM_BOOL T1_;
	int T2_;
	nimZeroMem((void*)(&res_1), sizeof(struct stat));
	T1_ = (NIM_BOOL)0;
	T2_ = (int)0;
	T2_ = lstat(nimToCStringConv(link_p0), (&res_1));
	T1_ = (((NI32)0) <= T2_);
	if (!(T1_)) goto LA3_;
	T1_ = S_ISLNK(res_1.st_mode);
LA3_: ;
	result = T1_;
	return result;
}
