* system mkdir [not found] <CAKfLWNo3MTYWNZj0G-giFSe8PkBsP+0P1J+C9u-nrvo0JfrZnw@mail.gmail.com> @ 2011-11-28 20:34 ` Fitzy 2011-11-28 20:50 ` Christopher Faylor 0 siblings, 1 reply; 5+ messages in thread From: Fitzy @ 2011-11-28 20:34 UTC (permalink / raw) To: cygwin Hello, I have a program which I wrote using Visual Studio 2010, everything works fine there. Now I'm trying to get it all running properly under Cygwin. It is compiling successfully, but the following does not work: system("mkdir temp"); I use this to create a temporary directory to which temporary files are written. It is then deleted when the program is finished. Under VS this command works, under Cygwin it does nothing. I've tried various alternatives "sudo mkdir temp" etc... But can't find anything that will programatically create a directory under Cygwin. Does anyone know how to do this? Thank you! -- Problem reports: http://cygwin.com/problems.html FAQ: http://cygwin.com/faq/ Documentation: http://cygwin.com/docs.html Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: system mkdir 2011-11-28 20:34 ` system mkdir Fitzy @ 2011-11-28 20:50 ` Christopher Faylor 2011-11-29 0:06 ` Eric Blake 0 siblings, 1 reply; 5+ messages in thread From: Christopher Faylor @ 2011-11-28 20:50 UTC (permalink / raw) To: cygwin On Mon, Nov 28, 2011 at 01:31:26PM -0700, Fitzy wrote: >?Hello, >? I have a program which I wrote using Visual Studio 2010, everything >works fine there. >Now I'm trying to get it all running properly under Cygwin. ?It is >compiling successfully, but the following does not work: >system("mkdir temp"); >I use this to create a temporary directory to which temporary files >are written. ?It is then deleted when the program is finished. >?Under VS this command works, under Cygwin it does nothing. ?I've >tried various alternatives >"sudo mkdir temp" etc... >?But can't find anything that will programatically create a directory >under Cygwin. > >?Does anyone know how to do this? Yes. Use the mkdir() function. That is, in fact, very similar to how it should be done in Visual Studio too. cgf -- Problem reports: http://cygwin.com/problems.html FAQ: http://cygwin.com/faq/ Documentation: http://cygwin.com/docs.html Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: system mkdir 2011-11-28 20:50 ` Christopher Faylor @ 2011-11-29 0:06 ` Eric Blake 2011-12-01 23:32 ` Peter Brown 0 siblings, 1 reply; 5+ messages in thread From: Eric Blake @ 2011-11-29 0:06 UTC (permalink / raw) To: cygwin [-- Attachment #1: Type: text/plain, Size: 566 bytes --] On 11/28/2011 01:33 PM, Christopher Faylor wrote: >> ?But can't find anything that will programatically create a directory >> under Cygwin. >> >> ?Does anyone know how to do this? > > Yes. Use the mkdir() function. That is, in fact, very similar to how it > should be done in Visual Studio too. For a temporary directory, mkdtemp() might be better than mkdir(); but either way, you still have to use rmdir() to clean up after you are done. -- Eric Blake eblake@redhat.com +1-919-301-3266 Libvirt virtualization library http://libvirt.org [-- Attachment #2: OpenPGP digital signature --] [-- Type: application/pgp-signature, Size: 620 bytes --] ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: system mkdir 2011-11-29 0:06 ` Eric Blake @ 2011-12-01 23:32 ` Peter Brown 2011-12-02 0:12 ` Eric Blake 0 siblings, 1 reply; 5+ messages in thread From: Peter Brown @ 2011-12-01 23:32 UTC (permalink / raw) To: cygwin Eric Blake <eblake <at> redhat.com> writes: > > On 11/28/2011 01:33 PM, Christopher Faylor wrote: > >> ?But can't find anything that will programatically create a directory > >> under Cygwin. > >> > >> ?Does anyone know how to do this? > > > > Yes. Use the mkdir() function. That is, in fact, very similar to how it > > should be done in Visual Studio too. > > For a temporary directory, mkdtemp() might be better than mkdir(); but > either way, you still have to use rmdir() to clean up after you are done. > This seems to work for me. int MySystem(char *s) { int answer; char syscmd[2048]; sprintf(syscmd,"cmd /c bash -c 'umask 0077;%s'",s); answer = system( syscmd ); return answer; } -- Problem reports: http://cygwin.com/problems.html FAQ: http://cygwin.com/faq/ Documentation: http://cygwin.com/docs.html Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: system mkdir 2011-12-01 23:32 ` Peter Brown @ 2011-12-02 0:12 ` Eric Blake 0 siblings, 0 replies; 5+ messages in thread From: Eric Blake @ 2011-12-02 0:12 UTC (permalink / raw) To: cygwin, pnbrown [-- Attachment #1: Type: text/plain, Size: 1690 bytes --] On 12/01/2011 04:32 PM, Peter Brown wrote: >>> Yes. Use the mkdir() function. That is, in fact, very similar to how it >>> should be done in Visual Studio too. I still say using mkdir() is the right solution - use a simple function, rather than a call to system(). > This seems to work for me. > > int MySystem(char *s) > { > int answer; > char syscmd[2048]; > sprintf(syscmd,"cmd /c bash -c 'umask 0077;%s'",s); > answer = system( syscmd ); > return answer; Ouch. A thousand times NOOOOO. DON'T DO THAT. You just made a HUGE security hole. All I have to do is call: MySystem("rm -rf /"); and I've nuked your system. Or, I could call MySystem(<string longer than 2048 bytes>) and stack overflow you. Or any other number of flaws. And even if those weren't issues, you ruined my quoting. I should be able to do system("echo 'a b'") and get "a b" on stdout, but the way you butchered quoting, my single quotes terminate the argument to cmd, and completely hose things. You DON'T want to use system() unless absolutely necessary, and then only with proper quoting. And you don't want to use sprintf on arbitrary input; stick to snprintf, or to asprintf. And seriously - calling cmd /c just to call bash just to call commands that will be interpreted by bash, when you could have just used commands interpreted by bash to begin with? If system() isn't calling cygwin's /bin/sh, then you aren't using cygwin properly. Don't make it worse by wrapping system() to go through another two layers of quoting nightmares. -- Eric Blake eblake@redhat.com +1-919-301-3266 Libvirt virtualization library http://libvirt.org [-- Attachment #2: OpenPGP digital signature --] [-- Type: application/pgp-signature, Size: 620 bytes --] ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2011-12-02 0:12 UTC | newest] Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- [not found] <CAKfLWNo3MTYWNZj0G-giFSe8PkBsP+0P1J+C9u-nrvo0JfrZnw@mail.gmail.com> 2011-11-28 20:34 ` system mkdir Fitzy 2011-11-28 20:50 ` Christopher Faylor 2011-11-29 0:06 ` Eric Blake 2011-12-01 23:32 ` Peter Brown 2011-12-02 0:12 ` Eric Blake
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).