473,396 Members | 1,940 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

linux coreutils 'basename' program question

hi group
the following lines are taken from basename.c of the linux coreutil
group of programs
i don't understand the meaning of several of the functions:

initialize_main (&argc, &argv); why initialize main ?

atexit (close_stdout); when do we need to do a close stdout ?
setlocale (LC_ALL, ""); why do we care about locale ?

bindtextdomain (PACKAGE, LOCALEDIR); ??
textdomain (PACKAGE); ??
btw: the coreutils are application level programs yet it seems to have
many elements only found in system level programs (a total newbie's
comment), and i find it quite hard to read and learn
int
main (int argc, char **argv)
{
char *name;

initialize_main (&argc, &argv);
program_name = argv[0];
setlocale (LC_ALL, "");
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);

atexit (close_stdout);

Oct 22 '07 #1
5 4614
David d'Angers wrote:
hi group
the following lines are taken from basename.c of the linux coreutil
group of programs
You'd probably do a lot better asking in a linux or gnu newsgroup or
forum, I'm afraid. We're not great on retrospective mindreading...

I'll make a few comments, but they're totally on the basis of ignorance
tempered by a brief scan of the manual pages for a few functions and a
quick Google.
int
main (int argc, char **argv)
{
char *name;

initialize_main (&argc, &argv);
I can't add much beyond the final comment in
http://www.hostingforum.ca/170773-wr...utilities.html
program_name = argv[0];
setlocale (LC_ALL, "");
According to my reading of the manual page, this ensures the locale has
been initialized in accordance with the environment settings.
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
Again, according to my reading of the manual pages, these initialize the
subsystem which will deal with message handling (ensuring that messages
tailored to the locale are displayed, I imagine).
atexit (close_stdout);
This is to ensure that the close_stdout routine (which perhaps does more
than just closing stdout) is called before the program exits.
Oct 22 '07 #2
David d'Angers wrote:
the following lines are taken from basename.c of the linux coreutil
group of programs
i don't understand the meaning of several of the functions:

initialize_main (&argc, &argv); why initialize main ?

atexit (close_stdout); when do we need to do a close stdout ?
Best ask in a Linux programming group.
>
setlocale (LC_ALL, ""); why do we care about locale ?
Turn the question around. Why do we not care about locale. Linux is
intended to be used on a variety of platforms in a variety of locales.
bindtextdomain (PACKAGE, LOCALEDIR); ??
textdomain (PACKAGE); ??
Ask your local Linux hacker.
>
btw: the coreutils are application level programs yet it seems to have
many elements only found in system level programs (a total newbie's
comment), and i find it quite hard to read and learn
See me comment about where Linux is expected to be run. In these sorts
of cases the difference between application and kernel takes on a new,
more specific, meaning.
Oct 22 '07 #3
David d'Angers wrote:
hi group
the following lines are taken from basename.c of the linux coreutil
group of programs
i don't understand the meaning of several of the functions:

initialize_main (&argc, &argv); why initialize main ?
This functions apparently performs some operations on main's arguments.
It is very probably checking and parsing the program's invocation
arguments, i.e. command-line parameters.
atexit (close_stdout); when do we need to do a close stdout ?
No idea. atexit() registers a function to be called upon normal
termination. Presumably the close_stdout() function closes open streams
and does some clean-up. Refer to it's source for more information.

All open streams are automatically closed upon normal program
termination, but still, it is better form to explicitly close them
yourself, if only to detect and report on errors.
setlocale (LC_ALL, ""); why do we care about locale ?
Just because you don't care about locale doesn't mean that a widely used
piece of software like basename can be so cavalier. This particular
call sets the entire locale to values based on implementation specific
environment variables.
bindtextdomain (PACKAGE, LOCALEDIR); ??
man bindtextdomain
textdomain (PACKAGE); ??
man textdomain
btw: the coreutils are application level programs yet it seems to have
many elements only found in system level programs (a total newbie's
comment), and i find it quite hard to read and learn
They are arguably system level programs. There is no sharp demarcation
between application level and system level programs. Programs vary from
end-user applications to system utilities, (like coreutils), and
libraries, to the OS kernel proper and perhaps even lower level code.

Also the precise meaning of these terms depend on the architecture and
operating system in use.

<snipped incomplete code>

Oct 22 '07 #4
Thanks Mark for the link
it's quite helpful
and everyone else too

next time i'll do more research first myself before making a post

Oct 22 '07 #5
Hi David,

about the setlocale(LC_ALL,""). We do that because by standard, all C
applications are started with the 'C' locale. So, localizations will
never work at all. To setup your application with the environment
locales you have to call setlocale(LC_ALL,""). Other else, you will
always receive English messages.

regards,
Otavio Ribeiro

On 22 out, 14:21, David d'Angers <liunst...@gmail.comwrote:
hi group
the following lines are taken from basename.c of the linux coreutil
group of programs
i don't understand the meaning of several of the functions:

initialize_main (&argc, &argv); why initialize main ?

atexit (close_stdout); when do we need to do a close stdout ?

setlocale (LC_ALL, ""); why do we care about locale ?

bindtextdomain (PACKAGE, LOCALEDIR); ??
textdomain (PACKAGE); ??

btw: the coreutils are application level programs yet it seems to have
many elements only found in system level programs (a total newbie's
comment), and i find it quite hard to read and learn

int
main (int argc, char **argv)
{
char *name;

initialize_main (&argc, &argv);
program_name = argv[0];
setlocale (LC_ALL, "");
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);

atexit (close_stdout);
Dec 9 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Jhuola Hoptire | last post by:
Just installed J2RE 1.4.2 on a Linux server. I am very knew to the POSIX world. I couldn't dig-up much in the docs or via google about the following: 1 - Is there a standard way to make sure...
14
by: Xah Lee | last post by:
Just bumped into another irresponsibility in perl. the crime in question this time is the module File::Basename. Reproduction: 1. create a directory containing a file of this name:...
12
by: Mike Dee | last post by:
A very very basic UTF-8 question that's driving me nuts: If I have this in the beginning of my Python script in Linux: #!/usr/bin/env python # -*- coding: UTF-8 -*- should I - or should I...
7
by: darktemplaaa | last post by:
Hello! I got IBM DB2 V8.1 successfully installed via rpm on my gentoo system except the DAS and the instance. When I run: /opt/IBM/db2/V8.1/instance/dascrt -u dasusr1 I get following error...
3
by: A.M | last post by:
Hi, I am planning to develop python applications on windows and run them on Linux. Are ActivePython scripts compatible with Linux? Is there any guideline that explains the compatibility...
1
by: Peter Saffrey | last post by:
I'd like to resurrect this subject: http://groups.google.com/group/comp.lang.python/browse_frm/thread/11146344b03e72b6/6b2a3b0c0e902114?lnk=gst&q=basename&rnum=2#6b2a3b0c0e902114 If I have a...
4
by: PengYu.UT | last post by:
libgen.h has the basename command. But it is not a C++ head file. Is there any C++ head file have a function or a class doing the same thing? Thanks, Peng
2
by: Thomas Ploch | last post by:
Hello, I have a cgi script that handles fileuploads from windows and *nix machines. i need os.path.basename(filename) to get the pure filename. For *nix, thats not a problem, but for windows,...
15
by: Konstantin Andreev | last post by:
I'm almost sure I've found bad bug, but for a while I can't neither confirm nor reject this. If anybody could make an independent test on it's own system, I'd appreciate it very much. The...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.