Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

It is the theory which decides what can be observed. -- Albert Einstein


devel / comp.lang.c / Re: Unix-y way to store records/structures within filesystem in C

SubjectAuthor
* Unix-y way to store records/structures within filesystem in CBithov Vinu Student
+- Re: Unix-y way to store records/structures within filesystem in CLew Pitcher
`- Re: Unix-y way to store records/structures within filesystem in Csongbird

1
Unix-y way to store records/structures within filesystem in C

<281cf765-1771-4549-9baf-9e2b8b886bb7n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19379&group=comp.lang.c#19379

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:ad4:5aa4:: with SMTP id u4mr40027986qvg.7.1639381532153;
Sun, 12 Dec 2021 23:45:32 -0800 (PST)
X-Received: by 2002:a0c:bed0:: with SMTP id f16mr41821493qvj.57.1639381531926;
Sun, 12 Dec 2021 23:45:31 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.c
Date: Sun, 12 Dec 2021 23:45:31 -0800 (PST)
Injection-Info: google-groups.googlegroups.com; posting-host=217.44.137.236; posting-account=_MjegQoAAABBdhnmr0o6IJGY5rlzUBmN
NNTP-Posting-Host: 217.44.137.236
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <281cf765-1771-4549-9baf-9e2b8b886bb7n@googlegroups.com>
Subject: Unix-y way to store records/structures within filesystem in C
From: vin...@calday.co.uk (Bithov Vinu Student)
Injection-Date: Mon, 13 Dec 2021 07:45:32 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Lines: 39
 by: Bithov Vinu Student - Mon, 13 Dec 2021 07:45 UTC

Hi,

I have data to store persistently with the following structure (flashcard):

- front
- back
- repetitions
- ease factor
- interval
- next review

As someone who learned programming through python, my knee-jerk instinct is to use SQLite to store/retrieve this data on the disk.

However, I've read the canonical Unix way of storing data with C is different, using the filesystem. Globbing, nftw and other functions and POSIX library features make this a reasonable task, but I was wondering, is there a standard layout/preferred layout for storing data like this? Do I create empty files with names that store variables that I can then parse (ie. after filtering with glob) or something else entirely?

Ideally my program would run on a per-user basis, ie. in the home directory of a given user:

~/.cards/<WHERE THE CARDS ARE STORED>

How would/should I store this data for efficiency and simplicity?

Thanks,
B

--
Student Account

--
Calday Grange Grammar School is a charitable company limited by guarantee
and registered in England and Wales with company number 8332696.
The
Registered Office is at Grammar School Lane, West Kirby, Wirral, CH48 8GG

Re: Unix-y way to store records/structures within filesystem in C

<sp7ri3$aid$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19389&group=comp.lang.c#19389

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: lew.pitc...@digitalfreehold.ca (Lew Pitcher)
Newsgroups: comp.lang.c
Subject: Re: Unix-y way to store records/structures within filesystem in C
Date: Mon, 13 Dec 2021 16:14:59 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 54
Message-ID: <sp7ri3$aid$1@dont-email.me>
References: <281cf765-1771-4549-9baf-9e2b8b886bb7n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Mon, 13 Dec 2021 16:14:59 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="b0ab253c5ad036dd3ee2dfcda070ea44";
logging-data="10829"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18KkiW9n5fQiFKBf9YZX22eKgkn69ZYvxs="
User-Agent: Pan/0.139 (Sexual Chocolate; GIT bf56508
git://git.gnome.org/pan2)
Cancel-Lock: sha1:4e00Xi3sp/EjGNsG1/EsNuF6X+U=
 by: Lew Pitcher - Mon, 13 Dec 2021 16:14 UTC

Hello, Bithov Vinu

On Sun, 12 Dec 2021 23:45:31 -0800, Bithov Vinu Student wrote:

> Hi,
>
> I have data to store persistently with the following structure
> (flashcard):
>
> - front - back - repetitions - ease factor - interval - next review

[snip]

> However, I've read the canonical Unix way of storing data with C is
> different, using the filesystem.

[snip]

> Ideally my program would run on a per-user basis, ie. in the home
> directory of a given user:
>
> ~/.cards/<WHERE THE CARDS ARE STORED>
>
> How would/should I store this data for efficiency and simplicity?

Ideally, you should ask this question in the comp.unix.programmer
newsgroup, as the answer depends more on the "Unix way of storing data"
than it does on C. (While it has it's origins in Unix, modern C is a
cross-platform language, which disguises and minimizes it's adherence
to "the Unix way".)

As for a C answer to your question, the best /I/ can do is "It depends".

/Where/ you store the data depends on the best-practices of Unix and
your installation. Offhand, I'd say that you are going in the right
direction with your dotfile/dotdirectory solution.

The /format/ of the data depends on how you intend to use the data,
both inside your program and in the Unix environment at large. The
canonical "Unix way" approach would be to have your program write
and read your data as textual data (I won't go into /why/, here.)

The /mechanism/ of your data manipulation, as far as comp.lang.c
is concerned should be restricted to the fopen()/fread()/fscanf()/
fwrite()/fprintf()/fclose() family of APIs. The "Unix way" also
includes many other POSIX APIs. It's your choice.

If you care to discuss your project further, you'll find us on
comp.unix.programmer

HTH
--
Lew Pitcher
"In Skills, We Trust"

Re: Unix-y way to store records/structures within filesystem in C

<81om8i-932.ln1@anthive.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19402&group=comp.lang.c#19402

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: songb...@anthive.com (songbird)
Newsgroups: comp.lang.c
Subject: Re: Unix-y way to store records/structures within filesystem in C
Date: Tue, 14 Dec 2021 09:58:16 -0500
Organization: the little wild kingdom
Lines: 25
Message-ID: <81om8i-932.ln1@anthive.com>
References: <281cf765-1771-4549-9baf-9e2b8b886bb7n@googlegroups.com>
Reply-To: songbird <songbird@anthive.com>
Injection-Info: reader02.eternal-september.org; posting-host="3ae97299e8c09770f19c8b539b61d675";
logging-data="18076"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/DoTwys3Ll9z94WBqNF+ZkiSt9+WaB2lc="
User-Agent: slrn/1.0.3 (Linux)
Cancel-Lock: sha1:KH/MYp/Um3HmsU0gxLInZbRlW/c=
 by: songbird - Tue, 14 Dec 2021 14:58 UTC

Bithov Vinu Student wrote:
....
> Ideally my program would run on a per-user basis, ie. in the home directory of a given user:
>
> ~/.cards/<WHERE THE CARDS ARE STORED>
....

in recent years the attempt to get away from the multiple dot
files under a users home directory of many linux distributions is
to use ~/.config/<program-name>/ as the place to store configuration
files and ~/.local/share/<program-name>/ as the place to store
program data.

note, that making sure the directory doesn't already exist is
important because if the user has already installed another
program with the same name then you don't want to clobber or
corrupt their previous work. card is a very generic name and
you may want to use something a bit more complicated to avoid
some chance of easy name collision.

if you intend this program to work for Macs or other systems
then the file system layout is different for those.

songbird

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor