Example #1
0
int safe_open(const char *path, int flags, ... ) {
    wchar_t *wpath = uncpath(path);
    int ret;

    if(!wpath)
	return -1;

    if(flags & O_CREAT) {
	int mode;
	va_list ap;
	va_start(ap, flags);
	mode = va_arg(ap, int);
	va_end(ap);
	ret = _wopen(wpath, flags, mode);
    } else
Example #2
0
DIR *opendir(const char *name) {
    DIR *d;
    DWORD attrs;
    int len;
    struct stat sb;
    wchar_t *wpath;

    if(stat(name, &sb) < 0)
	return NULL;

    if(!S_ISDIR(sb.st_mode)) {
	errno = ENOTDIR;
	return NULL;
    }
    if(!(d = cli_malloc(sizeof(*d)))) {
	errno = ENOMEM;
	return NULL;
    }
    wpath = uncpath(name);
    if(!wpath)
	return NULL;
    wcsncpy(d->entry, wpath, sizeof(d->entry) / sizeof(d->entry[0]));
    free(wpath);
    d->entry[sizeof(d->entry) / sizeof(d->entry[0])] = L'\0';
    len = wcslen(d->entry);

    if(len >= sizeof(d->entry) / sizeof(d->entry[0]) - 4) {
	free(d);
	errno = ENAMETOOLONG;
	return NULL;
    }
    while(len--) {
	if(d->entry[len] == L'\\')
	    d->entry[len] = L'\0';
	else
	    break;
    }

    wcsncat(d->entry, L"\\*.*", 4);
    d->dh = INVALID_HANDLE_VALUE;
    return d;
}