CAMLprim value win_findfirst(value name) { HANDLE h; value v; WIN32_FIND_DATA fileinfo; value valname = Val_unit; value valh = Val_unit; caml_unix_check_path(name, "opendir"); Begin_roots2 (valname,valh); h = FindFirstFile(String_val(name),&fileinfo); if (h == INVALID_HANDLE_VALUE) { DWORD err = GetLastError(); if (err == ERROR_NO_MORE_FILES) raise_end_of_file(); else { win32_maperr(err); uerror("opendir", Nothing); } } valname = copy_string(fileinfo.cFileName); valh = win_alloc_handle(h); v = alloc_small(2, 0); Field(v,0) = valname; Field(v,1) = valh; End_roots(); return v; }
CAMLprim value unix_link(value path1, value path2) { HMODULE hModKernel32; tCreateHardLink pCreateHardLink; hModKernel32 = GetModuleHandle("KERNEL32.DLL"); pCreateHardLink = (tCreateHardLink) GetProcAddress(hModKernel32, "CreateHardLinkA"); if (pCreateHardLink == NULL) invalid_argument("Unix.link not implemented"); caml_unix_check_path(path1, "link"); caml_unix_check_path(path2, "link"); if (! pCreateHardLink(String_val(path2), String_val(path1), NULL)) { win32_maperr(GetLastError()); uerror("link", path2); } return Val_unit; }
CAMLprim value unix_link(value path1, value path2) { CAMLparam2(path1, path2); char * p1; char * p2; int ret; caml_unix_check_path(path1, "link"); caml_unix_check_path(path2, "link"); p1 = caml_stat_strdup(String_val(path1)); p2 = caml_stat_strdup(String_val(path2)); caml_enter_blocking_section(); ret = link(p1, p2); caml_leave_blocking_section(); caml_stat_free(p1); caml_stat_free(p2); if (ret == -1) uerror("link", path2); CAMLreturn(Val_unit); }
CAMLprim value unix_stat_64(value path) { int ret; struct _stati64 buf; caml_unix_check_path(path, "stat"); ret = _stati64(String_val(path), &buf); if (ret == -1) uerror("stat", path); return stat_aux(1, &buf); }
CAMLprim value unix_lstat_64(value path) { struct _stat64 buf; __int64 st_ino; caml_unix_check_path(path, "lstat"); if (!do_stat(1, 1, String_val(path), NULL, &st_ino, &buf)) { uerror("lstat", path); } return stat_aux(1, st_ino, &buf); }
CAMLprim value unix_stat(value path) { struct _stat64 buf; __int64 st_ino; caml_unix_check_path(path, "stat"); if (!do_stat(0, 0, String_val(path), caml_string_length(path), NULL, &st_ino, &buf)) { uerror("stat", path); } return stat_aux(0, st_ino, &buf); }
CAMLprim value unix_unlink(value path) { CAMLparam1(path); char * p; int ret; caml_unix_check_path(path, "unlink"); p = caml_strdup(String_val(path)); caml_enter_blocking_section(); ret = unlink(p); caml_leave_blocking_section(); caml_stat_free(p); if (ret == -1) uerror("unlink", path); CAMLreturn(Val_unit); }
CAMLprim value unix_stat(value path) { int ret; struct _stati64 buf; caml_unix_check_path(path, "stat"); ret = _stati64(String_val(path), &buf); if (ret == -1) uerror("stat", path); if (buf.st_size > Max_long) { win32_maperr(ERROR_ARITHMETIC_OVERFLOW); uerror("stat", path); } return stat_aux(0, &buf); }
CAMLprim value unix_chmod(value path, value perm) { CAMLparam2(path, perm); char_os * p; int ret; caml_unix_check_path(path, "chmod"); p = caml_stat_strdup_to_os(String_val(path)); caml_enter_blocking_section(); ret = chmod_os(p, Int_val(perm)); caml_leave_blocking_section(); caml_stat_free(p); if (ret == -1) uerror("chmod", path); CAMLreturn(Val_unit); }
CAMLprim value unix_execvp(value path, value args) { char_os ** argv; char_os * wpath; caml_unix_check_path(path, "execvp"); argv = cstringvect(args, "execvp"); wpath = caml_stat_strdup_to_os(String_val(path)); (void) execvp_os((const char_os *)wpath, EXECV_CAST argv); caml_stat_free(wpath); cstringvect_free(argv); uerror("execvp", path); return Val_unit; /* never reached, but suppress warnings */ /* from smart compilers */ }
CAMLprim value unix_truncate(value path, value len) { CAMLparam2(path, len); char * p; int ret; caml_unix_check_path(path, "truncate"); p = caml_strdup(String_val(path)); caml_enter_blocking_section(); ret = truncate(p, Long_val(len)); caml_leave_blocking_section(); caml_stat_free(p); if (ret == -1) uerror("truncate", path); CAMLreturn(Val_unit); }
CAMLprim value unix_mkfifo(value path, value mode) { CAMLparam2(path, mode); char * p; int ret; caml_unix_check_path(path, "mkfifo"); p = caml_strdup(String_val(path)); caml_enter_blocking_section(); ret = mknod(p, (Int_val(mode) & 07777) | S_IFIFO, 0); caml_leave_blocking_section(); caml_stat_free(p); if (ret == -1) uerror("mkfifo", path); CAMLreturn(Val_unit); }
CAMLprim value unix_opendir(value path) { CAMLparam1(path); DIR * d; value res; char * p; caml_unix_check_path(path, "opendir"); p = caml_strdup(String_val(path)); caml_enter_blocking_section(); d = opendir(p); caml_leave_blocking_section(); caml_stat_free(p); if (d == (DIR *) NULL) uerror("opendir", path); res = alloc_small(1, Abstract_tag); DIR_Val(res) = d; CAMLreturn(res); }