PageRenderTime 41ms CodeModel.GetById 31ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

/ncftp-3.2.5/libncftp/c_rename.c

#
C | 44 lines | 32 code | 6 blank | 6 comment | 17 complexity | 37c0d24c54b0dbfdf35b45dd605239cf MD5 | raw file
Possible License(s): AGPL-3.0
 1/* c_rename.c
 2 *
 3 * Copyright (c) 1996-2005 Mike Gleason, NcFTP Software.
 4 * All rights reserved.
 5 *
 6 */
 7
 8#include "syshdrs.h"
 9#ifdef PRAGMA_HDRSTOP
10#	pragma hdrstop
11#endif
12
13int
14FTPRename(const FTPCIPtr cip, const char *const oldname, const char *const newname)
15{
16	int result;
17
18	if (cip == NULL)
19		return (kErrBadParameter);
20	if (strcmp(cip->magic, kLibraryMagic))
21		return (kErrBadMagic);
22	if ((oldname == NULL) || (oldname[0] == '\0'))
23		return (kErrBadParameter);
24	if ((newname == NULL) || (oldname[0] == '\0'))
25		return (kErrBadParameter);
26
27	
28	result = FTPCmd(cip, "RNFR %s", oldname);
29	if (result < 0)
30		return (result);
31	if (result != 3) {
32		cip->errNo = kErrRenameFailed;
33		return (cip->errNo);
34	}
35	
36	result = FTPCmd(cip, "RNTO %s", newname);
37	if (result < 0)
38		return (result);
39	if (result != 2) {
40		cip->errNo = kErrRenameFailed;
41		return (cip->errNo);
42	}
43	return (kNoErr);
44}	/* FTPRename */