linux - What is the simplest way for my C program to receive some file paths from configuration? -
i have application configurable via command line arguments
myprog -foofile 'foo.txt' -barfile 'bar.txt'
command line parameters bit cumbersome want allow other avenues these configurations bit disappointed looking more complicated taught should be.
solution 1: use environment variables
i make program myprog_foo_file
, myprog_bar_file
envorinment variables. implementation getenv
env variables global , add clutter , hard configure. specially gui apps because many window managers don't source ".profile" during initialization.
solution 2: use configuration file
since foofile , progfile kind of static configuration values, seems better put in configuration file somewhere:
foofile = /home/hugomg/foo.txt barfile = /home/hugomg/bar.txt
but afaik there no easy way in c read arbitrarily long string file. need make loop keeps reallocing buffer this?
alternatively, since values file names, there #define
somewhere specifying maximum size of path string?
your configuration file approach simple syntax looks me.
since on linux, use getline read file. can handle lines of arbitrary length , manages memory allocation you.
Comments
Post a Comment