Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linux equivalent of GetCommandLine and CommandLineToArgv?

Tags:

c

linux

api

I wonder if there are some API to get the current process' command line arguments on Linux.


I guess I was terribly unclear. The real purpose of the question was about passing unicode file names through command line arguments.

like image 925
lyxera Avatar asked Jan 05 '10 01:01

lyxera


1 Answers

Linux doesn't do "Unicode filenames" per se. All filenames are just random sequences of 8-bit characters as far as the kernel is concerned.

Bad things can happen, like the user can write a file and then change their locale, leaving their filename encoded in the previous locale. So if you're taking a filename as input, you need to preserve the exact 8-bit byte sequence passed to you in main(). If you need to display it to the user, try to interpret it in the encoding of the current locale and convert to your favorite type of Unicode.

On many modern Linux systems, the encoding will be UTF-8 so this will generally work OK.

like image 80
Brett Wilson Avatar answered Oct 08 '22 00:10

Brett Wilson