lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Mark Stroetzel Glasberg wrote:
>
> static int _ren(const char* fromName, const char* toName) {
> #ifdef WIN32
>    return MoveFileEx(fromName, toName, 
>       MOVEFILE_WRITE_THROUGH | MOVEFILE_COPY_ALLOWED);
> #else
>    sprintf(comm_buffer, "/bin/mv %s %s", fromName, toName);
>    int status = system(comm_buffer);
>    if (status != 0) return 0;
>    return 1;
> #endif
> }

Uhh... C_renItem("a b;rm -rf /",  "")

Be *really* careful with system()!!! 

Better use ANSI-C99 or POSIX functions.  I guess, any system that
has /bin/mv & co will have these functions.

ANSI-C99: int rename(const char *oldname, const char *newname)
ANSI-C99: int remove(const char *name)   (only files)
POSIX:    int rmdir(const char *name)
POSIX:    int mkdir(const char *pathname, mode_t mode)  (use mode 0777)

All 0 on success, -1 on error.

Ciao, ET.