~ubuntu-branches/debian/sid/gdal/sid

« back to all changes in this revision

Viewing changes to ogr/ogrsf_frmts/csv/ogrcsvdriver.cpp

  • Committer: Package Import Robot
  • Author(s): Francesco Paolo Lovergine
  • Date: 2012-05-07 15:04:42 UTC
  • mfrom: (5.5.16 experimental)
  • Revision ID: package-import@ubuntu.com-20120507150442-2eks97loeh6rq005
Tags: 1.9.0-1
* Ready for sid, starting transition.
* All symfiles updated to latest builds.
* Added dh_numpy call in debian/rules to depend on numpy ABI.
* Policy bumped to 3.9.3, no changes required.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/******************************************************************************
2
 
 * $Id: ogrcsvdriver.cpp 10645 2007-01-18 02:22:39Z warmerdam $
 
2
 * $Id: ogrcsvdriver.cpp 23016 2011-08-31 21:24:12Z rouault $
3
3
 *
4
4
 * Project:  CSV Translator
5
5
 * Purpose:  Implements OGRCSVDriver.
30
30
#include "ogr_csv.h"
31
31
#include "cpl_conv.h"
32
32
 
33
 
CPL_CVSID("$Id: ogrcsvdriver.cpp 10645 2007-01-18 02:22:39Z warmerdam $");
 
33
CPL_CVSID("$Id: ogrcsvdriver.cpp 23016 2011-08-31 21:24:12Z rouault $");
34
34
 
35
35
/************************************************************************/
36
36
/*                           ~OGRCSVDriver()                            */
74
74
/************************************************************************/
75
75
 
76
76
OGRDataSource *OGRCSVDriver::CreateDataSource( const char * pszName,
77
 
                                               char ** /* papszOptions */ )
 
77
                                               char **papszOptions )
78
78
 
79
79
{
80
80
/* -------------------------------------------------------------------- */
81
81
/*      First, ensure there isn't any such file yet.                    */
82
82
/* -------------------------------------------------------------------- */
83
 
    VSIStatBuf sStatBuf;
84
 
 
85
 
    if( VSIStat( pszName, &sStatBuf ) == 0 )
 
83
    VSIStatBufL sStatBuf;
 
84
 
 
85
    if (strcmp(pszName, "/dev/stdout") == 0)
 
86
        pszName = "/vsistdout/";
 
87
 
 
88
    if( VSIStatL( pszName, &sStatBuf ) == 0 )
86
89
    {
87
90
        CPLError( CE_Failure, CPLE_AppDefined, 
88
91
                  "It seems a file system object called '%s' already exists.",
92
95
    }
93
96
 
94
97
/* -------------------------------------------------------------------- */
95
 
/*      Create a directory.                                             */
 
98
/*      If the target is not a simple .csv then create it as a          */
 
99
/*      directory.                                                      */
96
100
/* -------------------------------------------------------------------- */
97
 
    if( VSIMkdir( pszName, 0755 ) != 0 )
98
 
    {
99
 
        CPLError( CE_Failure, CPLE_AppDefined, 
100
 
                  "Failed to create directory %s:\n%s", 
101
 
                  pszName, VSIStrerror( errno ) );
102
 
        return NULL;
 
101
    CPLString osDirName;
 
102
 
 
103
    if( EQUAL(CPLGetExtension(pszName),"csv") )
 
104
    {
 
105
        osDirName = CPLGetPath(pszName);
 
106
        if( osDirName == "" )
 
107
            osDirName = ".";
 
108
    }
 
109
    else
 
110
    {
 
111
        if( strncmp(pszName, "/vsizip/", 8) == 0)
 
112
        {
 
113
            /* do nothing */
 
114
        }
 
115
        else if( !EQUAL(pszName, "/vsistdout/") &&
 
116
            VSIMkdir( pszName, 0755 ) != 0 )
 
117
        {
 
118
            CPLError( CE_Failure, CPLE_AppDefined, 
 
119
                      "Failed to create directory %s:\n%s", 
 
120
                      pszName, VSIStrerror( errno ) );
 
121
            return NULL;
 
122
        }
 
123
        osDirName = pszName;
103
124
    }
104
125
 
105
126
/* -------------------------------------------------------------------- */
107
128
/* -------------------------------------------------------------------- */
108
129
    OGRCSVDataSource   *poDS = new OGRCSVDataSource();
109
130
 
110
 
    if( !poDS->Open( pszName, TRUE, TRUE ) )
 
131
    if( !poDS->Open( osDirName, TRUE, TRUE ) )
111
132
    {
112
133
        delete poDS;
113
134
        return NULL;
114
135
    }
115
136
 
 
137
    if( osDirName != pszName )
 
138
        poDS->SetDefaultCSVName( CPLGetFilename(pszName) );
 
139
 
116
140
    return poDS;
117
141
}
118
142