Path: blob/master/tools/testing/selftests/filesystems/fat/rename_exchange.c
26302 views
// SPDX-License-Identifier: GPL-2.0-or-later1/*2* Program that atomically exchanges two paths using3* the renameat2() system call RENAME_EXCHANGE flag.4*5* Copyright 2022 Red Hat Inc.6* Author: Javier Martinez Canillas <[email protected]>7*/89#define _GNU_SOURCE10#include <fcntl.h>11#include <stdio.h>12#include <stdlib.h>1314void print_usage(const char *program)15{16printf("Usage: %s [oldpath] [newpath]\n", program);17printf("Atomically exchange oldpath and newpath\n");18}1920int main(int argc, char *argv[])21{22int ret;2324if (argc != 3) {25print_usage(argv[0]);26exit(EXIT_FAILURE);27}2829ret = renameat2(AT_FDCWD, argv[1], AT_FDCWD, argv[2], RENAME_EXCHANGE);30if (ret) {31perror("rename exchange failed");32exit(EXIT_FAILURE);33}3435exit(EXIT_SUCCESS);36}373839