tronkko / dirent Goto Github PK
View Code? Open in Web Editor NEWC/C++ library for retrieving information on files and directories
License: MIT License
C/C++ library for retrieving information on files and directories
License: MIT License
Hello, tronkko.
Thank you for your unselfish work. I tested your programs and find one problem. That opendir method can not open folders named by chinese. It seems chinese word is wide charactor itself. Can you help to solve this problem? To make it work well both in English and Chinese.
Best Regards.
Xikang
Unlike other amazing repos, this repo's CONTRIBUTING.md looks plain and simple.
i think emojified, fun and precise version would be better!
Describe alternatives you've considered
An update would be amazing!
Additional context
If you are reading this, you are amazing! ⭐
Starred ⭐✔️
Thanks and regards,
Himanshu
It would be nice if this also included the headers ported to windows that are conveniently in this tar.gz file. (Note these was ripped from, a friend's linux install and I definitely need these to compile git with Visual Studio so that way it would become standalone and would not require cygwin or mingw to work and so I can easily drop the compiled git.exe in the windows directory and use it just fine.) I need it like this so I can do just that so I can use subprocess in python to open up git to get an lazy changelog to stuff. Also it would allow me to uninstall git for windows, mingw (trash), Github Desktop (trash gui), and also cygwin (also trash). The command line tool is by far the least trashy so I want to be able to build a pure windows build using MSVC.
By far your header helped on it as well.
A few local variables are declared at the beginning of functions despite of the detail that they are used only a bit later in these implementations.
Will it help to reduce the scope for such variables?
only get d_type(0) and d_name('?') with chinese file names.
Hello Toni,
Thanks for the libs. Good job.
I am using MacOS X, clang compiler. When trying to compile find.c, it rejects it because of
'PATH_MAX not defined or used'
PATH_MAX seems to be the max length of the files & directories names listed. So I fix it to 255 and it just works fine.
I hope you spend a fantastic day.
Thanks,
Harry
An extra null pointer check is not needed in the following functions.
Microsoft Visual Studio 2010
for _WIN64, file added locally.
Tried it, it doesn't work, lots of errors:
dirent.h(422): warning C4067: unexpected tokens following preprocessor directive - expected a newline
dirent.h(422): warning C4067: unexpected tokens following preprocessor directive - expected a newline
dirent.h(443): warning C4067: unexpected tokens following preprocessor directive - expected a newline
dirent.h(443): warning C4067: unexpected tokens following preprocessor directive - expected a newline
dirent.h(406): error C2275: '_WDIR' : illegal use of this type as an expression dirent.h(281) : see declaration of '_WDIR'
dirent.h(406): error C2065: 'dirp' : undeclared identifier
dirent.h(407): error C2065: 'dirp' : undeclared identifier
dirent.h(411): error C2065: 'dirp' : undeclared identifier
dirent.h(411): error C2223: left of '->handle' must point to struct/union
How do you think about to replace an if statement at the end of the function “dirent_mbstowcs_s” by the shorter statement “return (n > 0 && flag == 0) ? 0 : 1;
”?
If I try reading Japanese filenames in small directories theres no problem.
But as I do it in a folder with 800 files+ the type of files including Japanese chars is 0 and the name is ?
Would be nice to have a tag/release here to indicate what we should use and a version that gives us some context relative to previous releases.
this library do not implement these two functions:
https://pubs.opengroup.org/onlinepubs/9699919799/functions/seekdir.html
https://pubs.opengroup.org/onlinepubs/9699919799/functions/telldir.html
Does a year number need an update in the copyright information?
Hi. I found your API very usefull and easy to use on my small project I started on Windows,
I just had to do #include "dirent.h" and everything worked perfect.
However, I wish to make my program runnable on Ubuntu, but it obviously won't compile due to windows functionality inclusions/dependency on your code... Is dirent even intended to work on Linux distributions?
Is it possible to get my program to run on Ubuntu with none to minimal functionality alterations?
This is what my program does, and how it includes your functionalities, in case it where relevant:
https://gist.github.com/Mangonels/5e35a34594ceb5c2907dcdeefa80bc0c
Thank you!
opendir
doesn't handle path string properly with Russian localization.
OS: Windows 7
Localization: Russian
Steps to reproduce it:
* (Important) Set your Windows' formatting localization to Russian in the Control Panel
* Pass "Мои Документы" (My Documents in Russian) to `opendir`
* You'll find `mbstowcs_s` doesn't convert it correctly
/* Open directory stream using plain old C-string */
static DIR *opendir(const char *dirname)
{
...
/* Convert directory name to wide-character string */
wchar_t wname[PATH_MAX + 1];
size_t n;
int error = mbstowcs_s(&n, wname, PATH_MAX + 1, dirname, PATH_MAX+1);
if (error)
goto exit_failure;
...
}
Possible fix: use MultiByteToWideChar
instead of mbstowcs_s
/* Open directory stream using plain old C-string */
static DIR *opendir(const char *dirname)
{
...
/* Convert directory name to wide-character string */
wchar_t wname[PATH_MAX + 1];
int written = MultiByteToWideChar(CP_ACP, 0, dirname, -1, wname, PATH_MAX + 1);
if (written == 0)
goto exit_failure;
...
}
The version info in
src/dirent.h
is still at 1.23.1 instead of 1.23.2 in the top comment of the file in case of the released files:
https://github.com/tronkko/dirent/archive/1.23.2.zip
https://github.com/tronkko/dirent/archive/1.23.2.tar.gz
/* * Dirent interface for Microsoft Visual Studio * Version 1.23.1 * * Copyright (C) 2006-2012 Toni Ronkko * This file is part of dirent. Dirent may be freely distributed * under the MIT license. For all details and documentation, see * https://github.com/tronkko/dirent */
This can be corrected in the next release ...
error C2440: "=": Can not convert from "void *" to "dirent **"
error C2664: "void qsort (void *, :: size_t, :: size_t, _CoreCrtNonSecureSearchSortCompareFunction)": Can not convert parameter 4 from "void *" to "_CoreCrtNonSecureSearchSortCompareFunction"
When I use your .h in my project , the vs2017 said like it . I don't know what's the matter with it...
My installation of Linux has the following prototype for scandir
:
extern int scandir (const char *__restrict __dir,
struct dirent ***__restrict __namelist,
int (*__selector) (const struct dirent *),
int (*__cmp) (const struct dirent **,
const struct dirent **))
The difference between void
(your dirent) and dirent
(Linux) pointers for compare
causes problems in our project. Depending on the enabled warnings, you can't even pass alphasort
(which uses dirent
pointers in your code) to scandir
. A Visual Studio warning recommends to cast it, and that includes the __cdecl
convention - a macro which does not exist on other compilers.
So people patch this code for Visual Studio and by adding the cast, they break other platforms.
This cast should not be necessary in the first place - why is the prototype like this?
Can the prototype in your dirent.h
be changed to use dirent
pointers (on this repo)?
Hello,
I passed by this beautiful repo, and It was very helpful for one of my projects and I want to contribute to it by adding a code example that uses dirent library on visual studio to scan directories and list files with a specefic extension.
I wanted to do a pull request, but I need to be a contributor can you grant me that?
Thanks.
I would like to point out that an identifier like “_WDIR
” does eventually not fit to the expected naming convention of the C language standard.
Would you like to adjust your selection for unique names?
Does it support UTF-8 filenames (regardless of OS version and locale settings)?
C2362- Initialization of 'p' is skipped by 'goto exit_closedir' - line 414
C2362 - Initialization of 'ok' is skipped by 'goto exit_failure' - line 760
Hi,
I have the following error on Visual Studio 2013, since the addition of scandir():
C:\projects\dirent\include\dirent.h(917): error C2440: '=' : cannot convert from 'void *' to 'dirent *' [C:\projects\n2d2\build\N2D2-OS.vcxproj]
Conversion from 'void' to pointer to non-'void' requires an explicit cast
C:\projects\dirent\include\dirent.h(968): error C2664: 'void qsort(void *,size_t,size_t,int (__cdecl *)(const void *,const void *))' : cannot convert argument 4 from 'void *' to 'int (__cdecl *)(const void *,const void *)' [C:\projects\n2d2\build\N2D2-OS.vcxproj]
How do you think about an implementation of the functions “opendir” and “_wopendir” which can work without the local variable “error” if the source code would be adjusted in the way that the desired exception handling will be achieved by using goto statements?
Would you like to avoid an extra condition check at their ends?
Hi guys,
Would be nice if you include [scandir] in the <dirent.h> as well. It is defined in a newer POSIX standard here http://pubs.opengroup.org/onlinepubs/9699919799/. And found an implementation of scandir here http://www.fltk.org/strfiles/1779/scandir.c
I'm using <dirent.h> to compile libconfig in Windows and they use scandir in the implementation.
Thanks
Please add support for https://linux.die.net/man/3/readdir_r
dirent.h
doesn't support WinRT for a few reasons:
windef.h
directly causes fatal error C1189: #error : "No Target Architecture"
I think WinRT support can be added while maintaining compatibility with Win32:
windows.h
instead of windef.h
static int
_main(int argc, wchar_t *argv[])
{
/* ... */
}
should be
static int
_main(int argc, char *argv[])
{
/* ... */
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.