cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: create-dirs on win32

From: matthew b <mb7oo_at_hotmail.com>
Date: Tue, 07 Jan 2003 22:57:12 +0000

The stdio functions are typically provided by the language provider on
windows. So when you build with Microsoft Visual C++, you're using the "CRT"
or C run-time they provided. This is also related to why you can't pass
file* streams. Other systems (borland, cygwin, etc) will have different
implementations.

It does look like direct.h (as mentioned in someone else's reply) contains a
version of mkdir, though it doesn't have support for the mode; that would be
easy to workaround (just don't pass it, or define a macro or function to
remove it.).

So my current version is as follows; I don't have time to do any more with
this, or check if errno is set, but it makes things quite a bit cleaner

1) after the malloc, still set dirbuild[0] = '\0'; otherwise leave
create_dir_hierarchy alone.

2) somewhere (I stuck it in the #ifdef WIN32 at the top of the file, you may
want to put it elsewhere, and only for VC6), add the following:

#ifdef whatever-the-right-thing-is
#include <direct.h>
#define F_OK 0
// you might want to split this into declaration/definition, i just threw it
in main.c and thus didn't care.
// you might to use better name than mkdirWIN32hack. maybe mkdirNoMode
int mkdirWIN32hack(const char * sz, int mode)
{
    return mkdir(sz);
}
#define mkdir mkdirWIN32hack
#define mode_t int
#endif

--Matthew

>From: Daniel Stenberg <daniel_at_haxx.se>
>To: matthew b <mb7oo_at_hotmail.com>
>CC: libcurl Mailing list <curl-library_at_lists.sourceforge.net>
>Subject: Re: create-dirs on win32 Date: Tue, 7 Jan 2003 10:41:46 +0100
>(MET)
>MIME-Version: 1.0
>Received: from pm1.contactor.se ([193.15.23.130]) by
>mc8-f10.law1.hotmail.com with Microsoft SMTPSVC(5.0.2195.5600); Tue, 7 Jan
>2003 01:41:47 -0800
>Received: from localhost (dast_at_localhost)by pm1.contactor.se (8.9.3/8.9.1)
>with ESMTP id KAA11700;Tue, 7 Jan 2003 10:41:46 +0100 (MET)
>X-Authentication-Warning: pm1.contactor.se: dast owned process doing -bs
>X-X-Sender: dast_at_pm1.contactor.se
>In-Reply-To: <BAY1-F172jAg86386u400003904_at_hotmail.com>
>Message-ID: <Pine.GSO.4.50.0301071034100.903-100000_at_pm1.contactor.se>
>References: <BAY1-F172jAg86386u400003904_at_hotmail.com>
>Return-Path: daniel_at_haxx.se
>X-OriginalArrivalTime: 07 Jan 2003 09:41:47.0933 (UTC)
>FILETIME=[FF659CD0:01C2B630]
>
>On Mon, 6 Jan 2003, matthew b wrote:
>
> > Here's a diff for a real quick modification to create-dirs so it works
>on
> > win32. It also fixes a general 'uninitialized memory' bug. I didn't
>check
> > to see if the malloc succeeds, it looks like that's only done
> > inconsistently. I also didn't make any attempt at picking which error
> > happened to display to the user. I haven't tested the error condition at
> > all, just the simple test below.
>
>So mkdir() is not available in Windows?
>
>Could you then please rewrite your patch to instead make a function that
>looks and works like the unix version? Like this:
>
>(and add #define HAVE_MKDIR in the src/config-win32.h first)
>
>#ifndef HAVE_MKDIR
>#ifdef WIN32
>
>int mkdir(const char *pathname, mode_t mode)
>{
> int result;
> (void)mode; /* unused */
>
> result = CreateDirectory(pathname, NULL);
>
> /* mkdir returns 0 for success, opposite of CreateDirectory() */
> return result?0:-1;
>}
>
>#else
>/* system without mkdir and we have no implementation */
>int mkdir(const char *pathname, mode_t mode)
>{
> (void)mode; /* unused */
> (void)pathname; /* unused */
> return -1;
>#endif
>#endif
>
>It'll make the code in the function create_dir_hierarchy() look a lot
>nicer!
>
>--
> Daniel Stenberg -- curl, cURL, Curl, CURL. Groks URLs.

_________________________________________________________________
Add photos to your e-mail with MSN 8. Get 2 months FREE*.
http://join.msn.com/?page=features/featuredemail

-------------------------------------------------------
This SF.NET email is sponsored by:
SourceForge Enterprise Edition + IBM + LinuxWorld = Something 2 See!
http://www.vasoftware.com
Received on 2003-01-08