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 copy_filemodes(const char* source, const char* target)
{
    struct stat st;

    if (lstat(source, &st) != 0)
    {
        fprintf(stderr, "Error lstating %s: %s\n", source, strerror(errno));
        return 0;
    }

    if (chmod(target, st.st_mode) != 0)
    {
        fprintf(stderr, "Error chmoding %s: %s\n", source, strerror(errno));
        return 0;
    }

    if (lchown(target, st.st_uid, st.st_gid) != 0)
    {
        /* Hmm, this failed. Lets try a normal chown in case we
         * are running on a kernel that doesn't support lchown
         */
        if (errno == ENOSYS)
        {
            struct stat tst;

            if (lstat(target, &tst) != 0)
            {
                fprintf(stderr, "Error lstating %s: %s\n", target,
                        strerror(errno));
                return 0;
            }

            if (!S_ISLNK(tst.st_mode) &&
                chown(target, st.st_uid, st.st_gid) != 0)
            {
                fprintf(stderr, "Error lchowning %s: %s\n", source,
                        strerror(errno));
                return 0;
            }
        }
        else
        {
            fprintf(stderr, "Error lchowning %s: %s\n", source,
                    strerror(errno));
            return 0;
        }
    }

    return 1;
}
/* Copy the filemodes from one file to another
 */
Copy the filemodes from one file to another
Copy the filemodes from one file to another
int copy_filemodes(const char* source, const char* target)
{
    struct stat st;
    if (lstat(source, &st) != 0)
    {
        fprintf(stderr, "Error lstating %s: %s\n", source, strerror(errno));
        return 0;
    }
    if (chmod(target, st.st_mode) != 0)
    {
        fprintf(stderr, "Error chmoding %s: %s\n", source, strerror(errno));
        return 0;
    }
    if (lchown(target, st.st_uid, st.st_gid) != 0)
    {
        if (errno == ENOSYS)
        {
            struct stat tst;
            if (lstat(target, &tst) != 0)
            {
                fprintf(stderr, "Error lstating %s: %s\n", target,
                        strerror(errno));
                return 0;
            }
            if (!S_ISLNK(tst.st_mode) &&
                chown(target, st.st_uid, st.st_gid) != 0)
            {
                fprintf(stderr, "Error lchowning %s: %s\n", source,
                        strerror(errno));
                return 0;
            }
        }
        else
        {
            fprintf(stderr, "Error lchowning %s: %s\n", source,
                    strerror(errno));
            return 0;
        }
    }
    return 1;
}
int copy_filemodes ( const char * source , const char * target ) { struct stat st ; if ( lstat ( source , & st ) != 0 ) { fprintf ( stderr , " \n " , source , strerror ( errno ) ) ; return 0 ; } if ( chmod ( target , st . st_mode ) != 0 ) { fprintf ( stderr , " \n " , source , strerror ( errno ) ) ; return 0 ; } if ( lchown ( target , st . st_uid , st . st_gid ) != 0 ) { if ( errno == ENOSYS ) { struct stat tst ; if ( lstat ( target , & tst ) != 0 ) { fprintf ( stderr , " \n " , target , strerror ( errno ) ) ; return 0 ; } if ( ! S_ISLNK ( tst . st_mode ) && chown ( target , st . st_uid , st . st_gid ) != 0 ) { fprintf ( stderr , " \n " , source , strerror ( errno ) ) ; return 0 ; } } else { fprintf ( stderr , " \n " , source , strerror ( errno ) ) ; return 0 ; } } return 1 ; }
Copy the filemodes from one file to another
Copy the filemodes from one file to another
/* Hmm, this failed. Lets try a normal chown in case we
         * are running on a kernel that doesn't support lchown
         */