Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #163809 > unrolled thread

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

Started byBithov Vinu Student <vinub@calday.co.uk>
First post2021-12-12 23:45 -0800
Last post2021-12-14 09:58 -0500
Articles 3 — 3 participants

Back to article view | Back to comp.lang.c


Contents

  Unix-y way to store records/structures within filesystem in C Bithov Vinu Student <vinub@calday.co.uk> - 2021-12-12 23:45 -0800
    Re: Unix-y way to store records/structures within filesystem in C Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2021-12-13 16:14 +0000
    Re: Unix-y way to store records/structures within filesystem in C songbird <songbird@anthive.com> - 2021-12-14 09:58 -0500

#163809 — Unix-y way to store records/structures within filesystem in C

FromBithov Vinu Student <vinub@calday.co.uk>
Date2021-12-12 23:45 -0800
SubjectUnix-y way to store records/structures within filesystem in C
Message-ID<281cf765-1771-4549-9baf-9e2b8b886bb7n@googlegroups.com>
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

[toc] | [next] | [standalone]


#163819

FromLew Pitcher <lew.pitcher@digitalfreehold.ca>
Date2021-12-13 16:14 +0000
Message-ID<sp7ri3$aid$1@dont-email.me>
In reply to#163809
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"

[toc] | [prev] | [next] | [standalone]


#163832

Fromsongbird <songbird@anthive.com>
Date2021-12-14 09:58 -0500
Message-ID<81om8i-932.ln1@anthive.com>
In reply to#163809
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

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.c


csiph-web