ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
hi all
i am in strange problem.
i opend a terminal( am in root now)
enterd
cd Desktop
cd one
now am in one directory...
i am using a gtk filechooser...
it will select the file ..
and am giving a printf of the choosing file..
now am selected one->one.txt...
the print in the terminal is
/root/Desktop/one/one.txt....
my problem is..
i would like to choose a file with gtk filechooser
the file name is....
"one of file"...
the above directory or file having spaces
it will print in the termin a like
"/root/Desktop/one of file/one.txt"
here is the problem with space..
i wanna output like this
"/root/Desktop/one\ of\ file/txt"
If you are using filenames for other calls like system or popen, the problem is not only spaces. Filenames can use any character except /, and if it contains characters like '*[]" and so on, there will be problems. Here is a safer function:
This function works like the PHP function with the same name. In fact I looked at the PHP source to see how it did it. Just remember to free the result after you have used it.
IMHO
Using malloc in this way is very bad practice unless it's a specific
object allocation function.
you are asking for memory leaks by relying on callers to free what they use.
I agree. But the alternative is worse. Using a fixed length for a buffer might be overlooked easily. Like if the argument came from argv, or perhaps a file choser? Then we would have a security hole instead of a memory leak - much worse IMO.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.