Newer
Older
access-test / modules / src / test_rename.c
Nomura Kei on 5 Dec 2022 866 bytes update
/**
 * @file	test_rename.c
 * @brief	rename テスト
 * @author	Nomura Kei
 * @copyright 2008  Nomura Kei
 */
#include <stdio.h>
#include <errno.h>

#include <unistd.h>

#include <filetype.h>
#include <test_delete.h>


/**
 * 指定されたパスをリネームします。
 * パスが存在しない場合は、errno に ENOENT が設定され、false を返します。
 *
 * @param oldpath リネーム前のパス
 * @param newpath リネーム後のパス
 * @return true/false (リネーム成功/リネーム失敗)
 */
bool can_rename(const char* oldpath, const char* newpath)
{
	// リネーム前のパス存在有無確認 (存在しない場合 NG)
	bool is_error = !is_exists(oldpath);
	if (is_error)
	{
		errno = ENOENT;
		return false;
	}

	// リネーム
	int ret = rename(oldpath, newpath);
	bool is_success = (ret == 0);
	return is_success;
}