Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #138979 > unrolled thread
| Started by | Thiago Adams <thiago.adams@gmail.com> |
|---|---|
| First post | 2018-12-23 10:12 -0800 |
| Last post | 2018-12-30 10:34 -0800 |
| Articles | 14 — 8 participants |
Back to article view | Back to comp.lang.c
file system lib for C Thiago Adams <thiago.adams@gmail.com> - 2018-12-23 10:12 -0800
Re: file system lib for C Clark Smith <noaddress@nowhere.net> - 2018-12-23 20:20 +0000
Re: file system lib for C James Kuyper <jameskuyper@alumni.caltech.edu> - 2018-12-23 16:41 -0500
Re: file system lib for C Thiago Adams <thiago.adams@gmail.com> - 2018-12-30 10:33 -0800
Re: file system lib for C nobody@example.org (Scott) - 2018-12-30 20:42 +0000
Re: file system lib for C Thiago Adams <thiago.adams@gmail.com> - 2018-12-30 12:52 -0800
Re: file system lib for C rbowman <bowman@montana.com> - 2018-12-23 13:38 -0700
Re: file system lib for C Keith Thompson <kst-u@mib.org> - 2018-12-23 13:39 -0800
Re: file system lib for C Thiago Adams <thiago.adams@gmail.com> - 2018-12-30 11:09 -0800
Re: file system lib for C "Chris M. Thomasson" <invalid_chris_thomasson@invalid.invalid> - 2018-12-30 14:59 -0800
Re: file system lib for C rbowman <bowman@montana.com> - 2018-12-30 16:09 -0700
Re: file system lib for C nobody@example.org (Scott) - 2018-12-23 20:51 +0000
Re: file system lib for C jgh@mdfs.net - 2018-12-30 09:15 -0800
Re: file system lib for C Thiago Adams <thiago.adams@gmail.com> - 2018-12-30 10:34 -0800
| From | Thiago Adams <thiago.adams@gmail.com> |
|---|---|
| Date | 2018-12-23 10:12 -0800 |
| Subject | file system lib for C |
| Message-ID | <2156f362-0d1f-4e41-bbd9-bcc27344fe56@googlegroups.com> |
I started a new project on github that is a clone of C++ file system but for C. (I will add the functions I need on demand.) This is something I miss for C. If you don't know what std::filesystem is: https://en.cppreference.com/w/cpp/filesystem Some changes have to be made to adapt the code to C. I am adding a "fs_" suffix and copying functions that don´t use exceptions. C++ has a error object I am not sure what is the best design for C. For instance: bool create_directory( const std::filesystem::path& p, std::error_code& ec ) noexcept; I don't think error_code deserves a exactly copy https://en.cppreference.com/w/cpp/error/error_code because it is too complicated. Suggestions how to adapt this for C and contributions/critics are welcome.
[toc] | [next] | [standalone]
| From | Clark Smith <noaddress@nowhere.net> |
|---|---|
| Date | 2018-12-23 20:20 +0000 |
| Message-ID | <pvoqlq$sgo$1@news.albasani.net> |
| In reply to | #138979 |
On Sun, 23 Dec 2018 10:12:24 -0800, Thiago Adams wrote: > I started a new project on github that is a clone of C++ file system but > for C. (I will add the functions I need on demand.) > This is something I miss for C. > > If you don't know what std::filesystem is: > > https://en.cppreference.com/w/cpp/filesystem Looking into this link, doesn't C (at least under Unix) already offers roughly the same capabilities?
[toc] | [prev] | [next] | [standalone]
| From | James Kuyper <jameskuyper@alumni.caltech.edu> |
|---|---|
| Date | 2018-12-23 16:41 -0500 |
| Message-ID | <pvovee$lu6$1@dont-email.me> |
| In reply to | #138992 |
On 12/23/18 15:20, Clark Smith wrote: > On Sun, 23 Dec 2018 10:12:24 -0800, Thiago Adams wrote: > >> I started a new project on github that is a clone of C++ file system but >> for C. (I will add the functions I need on demand.) >> This is something I miss for C. >> >> If you don't know what std::filesystem is: >> >> https://en.cppreference.com/w/cpp/filesystem > > Looking into this link, doesn't C (at least under Unix) already > offers roughly the same capabilities? Unix provides a C interface for doing such things, but C itself does not.
[toc] | [prev] | [next] | [standalone]
| From | Thiago Adams <thiago.adams@gmail.com> |
|---|---|
| Date | 2018-12-30 10:33 -0800 |
| Message-ID | <8d2bb865-d09e-4fc3-ab53-3a41367a4f3e@googlegroups.com> |
| In reply to | #138992 |
On Sunday, December 23, 2018 at 6:20:19 PM UTC-2, Clark Smith wrote: > On Sun, 23 Dec 2018 10:12:24 -0800, Thiago Adams wrote: > > > I started a new project on github that is a clone of C++ file system but > > for C. (I will add the functions I need on demand.) > > This is something I miss for C. > > > > If you don't know what std::filesystem is: > > > > https://en.cppreference.com/w/cpp/filesystem > > Looking into this link, doesn't C (at least under Unix) already > offers roughly the same capabilities? Sure. Windows and Linux have it. But for cross platform code we need a common API. C++ has added this filesystem lib.
[toc] | [prev] | [next] | [standalone]
| From | nobody@example.org (Scott) |
|---|---|
| Date | 2018-12-30 20:42 +0000 |
| Message-ID | <5c292c09.1866820250@news.xmission.com> |
| In reply to | #139250 |
On Sun, 30 Dec 2018 10:33:31 -0800 (PST), Thiago Adams <thiago.adams@gmail.com> wrote: >On Sunday, December 23, 2018 at 6:20:19 PM UTC-2, Clark Smith wrote: >> On Sun, 23 Dec 2018 10:12:24 -0800, Thiago Adams wrote: >> >> > I started a new project on github that is a clone of C++ file system but >> > for C. (I will add the functions I need on demand.) >> > This is something I miss for C. >> > >> > If you don't know what std::filesystem is: >> > >> > https://en.cppreference.com/w/cpp/filesystem >> >> Looking into this link, doesn't C (at least under Unix) already >> offers roughly the same capabilities? > >Sure. Windows and Linux have it. >But for cross platform code we need a common API. >C++ has added this filesystem lib. Well...outside of mini/main class systems, where do you find any platform today that isn't Windows or, at heart, Unix-like?
[toc] | [prev] | [next] | [standalone]
| From | Thiago Adams <thiago.adams@gmail.com> |
|---|---|
| Date | 2018-12-30 12:52 -0800 |
| Message-ID | <71224529-ec7f-4fe8-8e04-a7b57118bc96@googlegroups.com> |
| In reply to | #139254 |
On Sunday, December 30, 2018 at 6:41:07 PM UTC-2, Scott wrote: > On Sun, 30 Dec 2018 10:33:31 -0800 (PST), Thiago Adams > wrote: > > >On Sunday, December 23, 2018 at 6:20:19 PM UTC-2, Clark Smith wrote: > >> On Sun, 23 Dec 2018 10:12:24 -0800, Thiago Adams wrote: > >> > >> > I started a new project on github that is a clone of C++ file system but > >> > for C. (I will add the functions I need on demand.) > >> > This is something I miss for C. > >> > > >> > If you don't know what std::filesystem is: > >> > > >> > https://en.cppreference.com/w/cpp/filesystem > >> > >> Looking into this link, doesn't C (at least under Unix) already > >> offers roughly the same capabilities? > > > >Sure. Windows and Linux have it. > >But for cross platform code we need a common API. > >C++ has added this filesystem lib. > > Well...outside of mini/main class systems, where do you find any > platform today that isn't Windows or, at heart, Unix-like? I need more than mkdir and the other APIS are different for other functions. For instance see directory_iterator. https://github.com/thradams/filesystem/blob/master/fs.h https://github.com/thradams/filesystem/blob/master/fs.c
[toc] | [prev] | [next] | [standalone]
| From | rbowman <bowman@montana.com> |
|---|---|
| Date | 2018-12-23 13:38 -0700 |
| Message-ID | <g8a9vsFplqbU1@mid.individual.net> |
| In reply to | #138979 |
On 12/23/2018 11:12 AM, Thiago Adams wrote:
> bool create_directory( const std::filesystem::path& p, std::error_code& ec ) noexcept;
>
> I don't think error_code deserves a exactly copy
> https://en.cppreference.com/w/cpp/error/error_code
> because it is too complicated.
>
> Suggestions how to adapt this for C and contributions/critics
> are welcome.
>
I'm not sure I understand your question but
#include <errno.h>
#include <string.h>
................
if (mkdir(path, mode) == -1) {
fprintf(stderr, "mkdir failed: %s\n", strerror(errno));
/* do whatever error recovery you need */
}
Check the man pages for the appropriate return. Ones that return an int
like mkdir() typically return -1 for an error condition. Those like
fopen() which return a FILE* return a null.
The <string.h> include is for strerror() which returns a descriptive
string. That's generally more useful than 'the error was 23'.
[toc] | [prev] | [next] | [standalone]
| From | Keith Thompson <kst-u@mib.org> |
|---|---|
| Date | 2018-12-23 13:39 -0800 |
| Message-ID | <lnbm5bdith.fsf@kst-u.example.com> |
| In reply to | #138995 |
rbowman <bowman@montana.com> writes:
> On 12/23/2018 11:12 AM, Thiago Adams wrote:
>> bool create_directory( const std::filesystem::path& p, std::error_code& ec ) noexcept;
>>
>> I don't think error_code deserves a exactly copy
>> https://en.cppreference.com/w/cpp/error/error_code
>> because it is too complicated.
>>
>> Suggestions how to adapt this for C and contributions/critics
>> are welcome.
>>
>
> I'm not sure I understand your question but
>
> #include <errno.h>
> #include <string.h>
> ................
> if (mkdir(path, mode) == -1) {
> fprintf(stderr, "mkdir failed: %s\n", strerror(errno));
> /* do whatever error recovery you need */
> }
mkdir() requires `#include <sys/stat.h>`, which is POSIX-specific and
not part of the C standard. C++'s std::filesystem (new in C++17) is, I
think, intended to be more general.
[...]
--
Keith Thompson (The_Other_Keith) kst@mib.org <http://www.ghoti.net/~kst>
Will write code for food.
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
[toc] | [prev] | [next] | [standalone]
| From | Thiago Adams <thiago.adams@gmail.com> |
|---|---|
| Date | 2018-12-30 11:09 -0800 |
| Message-ID | <79bd4cad-0614-487e-af19-e9747da4eb1d@googlegroups.com> |
| In reply to | #138999 |
On Sunday, December 23, 2018 at 7:39:13 PM UTC-2, Keith Thompson wrote:
> rbowman writes:
> > On 12/23/2018 11:12 AM, Thiago Adams wrote:
> >> bool create_directory( const std::filesystem::path& p, std::error_code& ec ) noexcept;
> >>
> >> I don't think error_code deserves a exactly copy
> >> https://en.cppreference.com/w/cpp/error/error_code
> >> because it is too complicated.
> >>
> >> Suggestions how to adapt this for C and contributions/critics
> >> are welcome.
> >>
> >
> > I'm not sure I understand your question but
> >
> > #include <errno.h>
> > #include <string.h>
> > ................
> > if (mkdir(path, mode) == -1) {
> > fprintf(stderr, "mkdir failed: %s\n", strerror(errno));
> > /* do whatever error recovery you need */
> > }
>
> mkdir() requires `#include <sys/stat.h>`, which is POSIX-specific and
> not part of the C standard. C++'s std::filesystem (new in C++17) is, I
> think, intended to be more general.
>
> [...]
>
Some libraries like atomic and threads first were
added into C++ and later added into C.
Compare:
https://en.cppreference.com/w/cpp/thread
with
https://en.cppreference.com/w/c/thread
In my cross platform code I need create dir, iterate etc.
So I thought a filesystem for C could be based on the C++
version, similar of what happened with threads.
The advantage if that you have to learn just once.
I am not sure if in this case we have enough benefits
cloning C++. Maybe traditional mkdir is better.
Windows has _mkdir that is very similar.
https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/mkdir-wmkdir?view=vs-2017
and also sets errno.
I could create fs_mkdir that calls _mkdir on windows and mkdir on linux.
But I also need a way to iterate directories and more.
I want to have at least 3 projects for cross plataform
code.
1 - console (https://github.com/thradams/conio)
2 - filesystem (https://github.com/thradams/filesystem)
3 - sockets (https://github.com/thradams/Sockets)
I already use a project called tinycthread
https://github.com/tinycthread/tinycthread
that has what I need for threads.
For sockets, even when windows has the same function,
lets say 'recv' the way of reporting error is different.
Linux sets errno and windows has WSAGetLastError .
http://man7.org/linux/man-pages/man2/recv.2.html
https://docs.microsoft.com/en-us/windows/desktop/api/winsock/nf-winsock-recv
The error number is also different
Windows:
WSAEACCES 10013
Linux
EACCES 13
So in this case I may add a parameter to return the error instead
of use errno or WSAGetLastError.
Another option could be translate WSAEACCES and set errno then both
function would have the same behavior.
[toc] | [prev] | [next] | [standalone]
| From | "Chris M. Thomasson" <invalid_chris_thomasson@invalid.invalid> |
|---|---|
| Date | 2018-12-30 14:59 -0800 |
| Message-ID | <q0bikl$ts6$1@dont-email.me> |
| In reply to | #139252 |
On 12/30/2018 11:09 AM, Thiago Adams wrote:
> On Sunday, December 23, 2018 at 7:39:13 PM UTC-2, Keith Thompson wrote:
>> rbowman writes:
>>> On 12/23/2018 11:12 AM, Thiago Adams wrote:
>>>> bool create_directory( const std::filesystem::path& p, std::error_code& ec ) noexcept;
>>>>
>>>> I don't think error_code deserves a exactly copy
>>>> https://en.cppreference.com/w/cpp/error/error_code
>>>> because it is too complicated.
>>>>
>>>> Suggestions how to adapt this for C and contributions/critics
>>>> are welcome.
>>>>
>>>
>>> I'm not sure I understand your question but
>>>
>>> #include <errno.h>
>>> #include <string.h>
>>> ................
>>> if (mkdir(path, mode) == -1) {
>>> fprintf(stderr, "mkdir failed: %s\n", strerror(errno));
>>> /* do whatever error recovery you need */
>>> }
>>
>> mkdir() requires `#include <sys/stat.h>`, which is POSIX-specific and
>> not part of the C standard. C++'s std::filesystem (new in C++17) is, I
>> think, intended to be more general.
>>
>> [...]
>>
>
>
> Some libraries like atomic and threads first were
> added into C++ and later added into C.
[...]
How many compilers support C11 threads and atomics? So far, I can only
find one.
[toc] | [prev] | [next] | [standalone]
| From | rbowman <bowman@montana.com> |
|---|---|
| Date | 2018-12-30 16:09 -0700 |
| Message-ID | <g8t1f3FqvidU1@mid.individual.net> |
| In reply to | #139252 |
On 12/30/2018 12:09 PM, Thiago Adams wrote: > Windows has _mkdir that is very similar. > > https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/mkdir-wmkdir?view=vs-2017 > > and also sets errno. I don't remember exactly when MS got religion but you'll see a number of POSIX functions that were supported with a disclaimer: This POSIX function is deprecated. Use the ISO C++ conformant _xxxx instead. It would be interesting to look under the hood to see if anything really has changed. Life would be simpler if MS had been fully POSIX and ISO compliant all along. Also, as you mention, they got into sockets relatively late, did it their own way, and it doesn't always work the way you expect. It keeps cross platform work interesting.
[toc] | [prev] | [next] | [standalone]
| From | nobody@example.org (Scott) |
|---|---|
| Date | 2018-12-23 20:51 +0000 |
| Message-ID | <5c1ff44d.1262728562@news.xmission.com> |
| In reply to | #138979 |
On Sun, 23 Dec 2018 10:12:24 -0800 (PST), Thiago Adams <thiago.adams@gmail.com> wrote: > >I started a new project on github that is a clone >of C++ file system but for C. (I will add the functions I need=20 >on demand.) >This is something I miss for C. > >If you don't know what std::filesystem is: > >https://en.cppreference.com/w/cpp/filesystem ... >bool create_directory( const std::filesystem::path& p, std::error_code& ec = >) noexcept; ... >Suggestions how to adapt this for C and contributions/critics >are welcome. One question that immediately occurs: is there something wrong with mkdir(2)? What problem do you perceive that you're trying to solve?
[toc] | [prev] | [next] | [standalone]
| From | jgh@mdfs.net |
|---|---|
| Date | 2018-12-30 09:15 -0800 |
| Message-ID | <ab53b17a-41c8-45d7-bb65-55da24a7463f@googlegroups.com> |
| In reply to | #138979 |
Thiago Adams wrote: > I am adding a "fs_" suffix and copying functions > that don´t use exceptions. That's a prefix.
[toc] | [prev] | [next] | [standalone]
| From | Thiago Adams <thiago.adams@gmail.com> |
|---|---|
| Date | 2018-12-30 10:34 -0800 |
| Message-ID | <68f00aa6-419d-44b8-a454-afcdc828e471@googlegroups.com> |
| In reply to | #139247 |
On Sunday, December 30, 2018 at 3:15:26 PM UTC-2, j...@mdfs.net wrote: > Thiago Adams wrote: > > I am adding a "fs_" suffix and copying functions > > that don´t use exceptions. > > That's a prefix. Thanks. :)
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.c
csiph-web