openbmc/build/tmp/deploy/sdk/witherspoon-2019-08-08/sysroots/armv6-openbmc-linux-gnueabi/usr/src/debug/base-passwd/3.5.29-r0/base-passwd-3.5.29/update-passwd.c
int replace_file(const char* org, const char* new, const char* backup)
{
    if (backup)
    {
        int res;

        if ((res = link(org, backup)) == -1)
        {
            if (errno == EEXIST)
            {
                if (unlink(backup) == -1)
                {
                    fprintf(stderr, "Error unlinking old backupfile %s: %s\n",
                            backup, strerror(errno));
                    return 0;
                }
                res = link(org, backup);
            }
            if (res == -1)
            {
                fprintf(stderr, "Error making backupfile %s: %s\n", backup,
                        strerror(errno));
                return 0;
            }
        }
    }

    if (rename(new, org) == -1)
    {
        fprintf(stderr, "Error: failed to replace %s with %s: %s\n", org, new,
                strerror(errno));
        return 0;
    }

    return 1;
}
/* Atomically replace a file with another, possibly keeping a backup file.
 * Taken from the dpkg2 sourcetree.
 */
Atomically replace a file with another, possibly keeping a backup file.
Taken from the dpkg2 sourcetree.
Atomically replace a file with another possibly keeping a backup file . Taken from the dpkg2 sourcetree .
int replace_file(const char* org, const char* new, const char* backup)
{
    if (backup)
    {
        int res;
        if ((res = link(org, backup)) == -1)
        {
            if (errno == EEXIST)
            {
                if (unlink(backup) == -1)
                {
                    fprintf(stderr, "Error unlinking old backupfile %s: %s\n",
                            backup, strerror(errno));
                    return 0;
                }
                res = link(org, backup);
            }
            if (res == -1)
            {
                fprintf(stderr, "Error making backupfile %s: %s\n", backup,
                        strerror(errno));
                return 0;
            }
        }
    }
    if (rename(new, org) == -1)
    {
        fprintf(stderr, "Error: failed to replace %s with %s: %s\n", org, new,
                strerror(errno));
        return 0;
    }
    return 1;
}
int replace_file ( const char * org , const char * new , const char * backup ) { if ( backup ) { int res ; if ( ( res = link ( org , backup ) ) == -1 ) { if ( errno == EEXIST ) { if ( unlink ( backup ) == -1 ) { fprintf ( stderr , " \n " , backup , strerror ( errno ) ) ; return 0 ; } res = link ( org , backup ) ; } if ( res == -1 ) { fprintf ( stderr , " \n " , backup , strerror ( errno ) ) ; return 0 ; } } } if ( rename ( new , org ) == -1 ) { fprintf ( stderr , " \n " , org , new , strerror ( errno ) ) ; return 0 ; } return 1 ; }
Atomically replace a file with another, possibly keeping a backup file.
Atomically replace a file with another possibly keeping a backup file .