[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Create, move and rename files and folder???
- From: Edgar Toernig <froese@...>
- Date: Sat, 10 Apr 2004 05:55:49 +0200
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.