¿Alguien sabe una funcion equivalente a _splitpath de windows en linux? en windows esta en el stdlib, pero en linux no
La tienes que implementar, hay varias rondando. Te dejo una:
#ifndef __SPLITPATH_HPP__
#define __SPLITPATH_HPP__
#ifdef UNIX
void _splitpath(const char* path, char* drive, char* dir,
char* fname, char* ext);
#endif
#endif
#ifndef WIN32
#include <config.h>
#include <stdio.h>
#include <string.h>
#include "SplitPath.hpp"
// copia parcial de strings
static inline void strcpypart(char* dest, const char* src, size_t size)
{
memcpy(dest, src, size);
dest[size] = 0;
}
void _splitpath(const char* path, char* drive, char* dir,
char* fname, char* ext)
{
if(drive)
strcpy(drive, "");
const char* lastslash = 0;
for(const char* p = path; *p != '\0'; p++) {
if(*p == '/')
lastslash = p;
}
if(dir) {
if(lastslash == 0)
strcpy(dir, "");
else
strcpypart(dir, path, lastslash - path + 1);
}
const char* lastdot = 0;
const char* begin = (lastslash != 0) ? lastslash+1 : path;
for(const char* p = begin; *p != '\0'; p++) {
if(*p == '.')
lastdot = p;
}
if(lastdot==0) {
if(fname)
strcpy(fname, begin);
if(ext)
strcpy(ext, "");
} else {
if(fname)
strcpypart(fname, begin, lastdot - begin);
if(ext)
strcpy(ext, lastdot);
}
//printf ("Path: %s => %s - %s - %s - %s.\n", path,
// drive, dir, fname, ext);
}
#endif
Yo (incluso en Windows) uso el modulo boost::filesystem. Si vas a linkear estaticamente (y te sobra 1GB) puedes compilar las Boost enteras y el ya te va incluyendo las .lib propiadas con pragma. Ahora, si no tienes muchas ganas, trasteando un par de hpp y compilando el modulo por separado ya sirve (esto es lo que hago yo).
Gracias a los dos, por ahora me decanto mas a la opcion de ZüNdFoLGe.