Beispiel #1
0
void bootstrap() {
  process = malloc(sizeof(process_t));
  process->cwd = st_new(MAX_PATH, st_enc_utf8);
  size_t size = 1027;
  int err = uv_cwd(process->cwd->value, &size);
  assert(err == 0);
}
Beispiel #2
0
static void
module_on_scandir(uv_fs_t *req)
{
    uv_dirent_t dirEntry;
    char currentPath[512];
    size_t size;

    size = sizeof(currentPath);

    uv_cwd(currentPath, &size);
    uv_chdir(req->path);

    while(uv_fs_scandir_next(req, &dirEntry) != UV_EOF)
    {
        const char *extension;

        if(dirEntry.type != UV_DIRENT_FILE)
        {
            continue;
        }

        extension = module_get_extension(dirEntry.name);
        if(extension == NULL ||
           strcmp(module_get_extension(dirEntry.name), "so") != 0)
        {
            continue;
        }

        module_load(dirEntry.name);
    }

    uv_chdir(currentPath);
}
Beispiel #3
0
std::string cwd() {
#if UV_VERSION_MAJOR == 0 && UV_VERSION_MINOR <= 10
    char dir[512];
    uv_cwd(dir, 512);
    return dir;
#else
    size_t max = 0;
    std::string dir;
    do {
        max += 256;
        dir.resize(max);
        uv_cwd(const_cast<char *>(dir.data()), &max);
    } while (max == dir.size());
    dir.resize(max - 1);
    return dir;
#endif
}
Beispiel #4
0
static int luv_cwd(lua_State* L) {
  size_t size = 2*PATH_MAX;
  char path[2*PATH_MAX];
  int ret = uv_cwd(path, &size);
  if (ret < 0) return luv_error(L, ret);
  lua_pushlstring(L, path, size);
  return 1;
}
Beispiel #5
0
/*
 * Get name of current directory into buffer 'buf' of length 'len' bytes.
 * Return OK for success, FAIL for failure.
 */
int mch_dirname(char_u *buf, int len)
{
  int errno;
  if ((errno = uv_cwd((char *) buf, len)) != 0) {
      STRCPY(buf, uv_strerror(errno));
      return FAIL;
  }
  return OK;
}
Beispiel #6
0
static int LuaIO_process_cwd(lua_State* L) {
  char buf[PATH_MAX];
  size_t length = sizeof(buf);

  int err = uv_cwd(buf, &length);
  if (err < 0) return luaL_error(L, "process.cwd() uv_cwd() error: %s\n", uv_strerror(err));
  lua_pushlstring(L, buf, strlen(buf));

  return 1;
}
Beispiel #7
0
int os_dirname(char_u *buf, size_t len)
{
  assert(buf && len);

  int errno;
  if ((errno = uv_cwd((char *)buf, &len)) != 0) {
    vim_strncpy(buf, (char_u *)uv_strerror(errno), len - 1);
    return FAIL;
  }
  return OK;
}
Beispiel #8
0
/// Get the name of current directory.
///
/// @param buf Buffer to store the directory name.
/// @param len Length of `buf`.
/// @return `OK` for success, `FAIL` for failure.
int os_dirname(char_u *buf, size_t len)
{
  assert(buf && len);

  int error_number;
  if ((error_number = uv_cwd((char *)buf, &len)) != kLibuvSuccess) {
    STRLCPY(buf, uv_strerror(error_number), len);
    return FAIL;
  }
  return OK;
}
Beispiel #9
0
static int luvit_getcwd(lua_State* L) {
  uv_err_t rc;

  rc = uv_cwd(getbuf, ARRAY_SIZE(getbuf) - 1);
  if (rc.code != UV_OK) {
    return luaL_error(L, "luvit_getcwd: %s\n", strerror(errno));
  }

  getbuf[ARRAY_SIZE(getbuf) - 1] = '\0';
  lua_pushstring(L, getbuf);
  return 1;
}
Beispiel #10
0
static int process_cwd(lua_State* L) {
  size_t size = 2*PATH_MAX - 1;
  char path[2*PATH_MAX];
  uv_err_t err;

  err = uv_cwd(path, size);
  if (err.code != UV_OK) {
    return luaL_error(L, "uv_cwd: %s", uv_strerror(err));
  }

  lua_pushstring(L, path);
  return 1;
}
Beispiel #11
0
/* Get the current working directory. */
MVMString * MVM_dir_cwd(MVMThreadContext *tc) {
#ifdef _WIN32
    char path[MAX_PATH];
    const size_t max_path = MAX_PATH;
#else
    char path[PATH_MAX];
    const size_t max_path = PATH_MAX;
#endif
    int r;

    if ((r = uv_cwd(path, max_path)) < 0) {
        MVM_exception_throw_adhoc(tc, "chdir failed: %s", uv_strerror(r));
    }

    return MVM_string_utf8_decode(tc, tc->instance->VMString, path, strlen(path));
}
Beispiel #12
0
// taken from Node.js: function Cwd in node.cc
std::string default_realm_file_directory()
{
#ifdef _WIN32
  /* MAX_PATH is in characters, not bytes. Make sure we have enough headroom. */
  char buf[MAX_PATH * 4];
#else
  char buf[PATH_MAX];
#endif
    
    size_t cwd_len = sizeof(buf);
    int err = uv_cwd(buf, &cwd_len);
    if (err) {
        throw UVException(static_cast<uv_errno_t>(err));
    }

    return std::string(buf, cwd_len);
}
Beispiel #13
0
/*
 * Class:     com_iwebpp_libuvpp_LibUV
 * Method:    _cwd
 * Signature: ()Ljava/lang/String;
 */
extern "C" JNIEXPORT  jstring JNICALL Java_com_iwebpp_libuvpp_LibUV__1cwd
(JNIEnv *env, jclass cls) {

#ifdef _WIN32
    /* MAX_PATH is in characters, not bytes. Make sure we have enough headroom. */
    char buf[MAX_PATH * 4 + 1];
#else
    char buf[PATH_MAX + 1];
#endif

    uv_err_t r = uv_cwd(buf, ARRAY_SIZE(buf) - 1);
    if (r.code != UV_OK) {
        ThrowException(env, r.code, "uv_cwd");
        return NULL;
    }
    buf[ARRAY_SIZE(buf) - 1] = '\0';
    return env->NewStringUTF(buf);
}
Beispiel #14
0
static value_t fl_path_cwd(value_t *args, uint32_t nargs)
{
    uv_err_t err;
    if (nargs > 1)
        argcount("path.cwd", nargs, 1);
    if (nargs == 0) {
        char buf[1024];
        err = uv_cwd(buf, sizeof(buf));
        if (err.code != UV_OK)
          lerrorf(IOError, "path.cwd: could not get cwd: %s", uv_strerror(err));
        return string_from_cstr(buf);
    }
    char *ptr = tostring(args[0], "path.cwd");
    err = uv_chdir(ptr);
    if (err.code != UV_OK)
        lerrorf(IOError, "path.cwd: could not cd to %s: %s", ptr, uv_strerror(err));
    return FL_T;
}
Beispiel #15
0
DLLEXPORT int jl_cwd(char *buffer, size_t size)
{
    return uv_cwd(buffer,size);
}