⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 beos.c

📁 完整的解压zip文件的源码。包含密码功能
💻 C
📖 第 1 页 / 共 3 页
字号:
    }} /* end function close_outfile() */#ifdef SET_DIR_ATTRIB/* messages of code for setting directory attributes */static char Far DirlistUidGidFailed[] =  "warning:  cannot set UID %d and/or GID %d for %s\n";static char Far DirlistUtimeFailed[] =  "warning:  cannot set modification, access times for %s\n";#  ifndef NO_CHMOD  static char Far DirlistChmodFailed[] =    "warning:  cannot set permissions for %s\n";#  endifint set_direc_attribs(__G__ d)    __GDEF    dirtime *d;{    int errval = PK_OK;    if (d->have_uidgid &&        chown(d->fn, (uid_t)d->uidgid[0], (gid_t)d->uidgid[1]))    {        Info(slide, 0x201, ((char *)slide,          LoadFarString(DirlistUidGidFailed),          d->uidgid[0], d->uidgid[1], d->fn));        if (!errval)            errval = PK_WARN;    }    if (utime(d->fn, (const struct utimbuf *)&d->u.t2)) {        Info(slide, 0x201, ((char *)slide,          LoadFarString(DirlistUtimeFailed), d->fn));        if (!errval)            errval = PK_WARN;    }#ifndef NO_CHMOD    if (chmod(d->fn, 0xffff & d->perms)) {        Info(slide, 0x201, ((char *)slide,          LoadFarString(DirlistChmodFailed), d->fn));        /* perror("chmod (file attributes) error"); */        if (!errval)            errval = PK_WARN;    }#endif /* !NO_CHMOD */    return errval;} /* end function set_directory_attributes() */#endif /* SET_DIR_ATTRIB */#ifdef TIMESTAMP/***************************//*  Function stamp_file()  *//***************************/int stamp_file(fname, modtime)    ZCONST char *fname;    time_t modtime;{    struct utimbuf tp;    tp.modtime = tp.actime = modtime;    return (utime(fname, &tp));} /* end function stamp_file() */#endif /* TIMESTAMP */#ifndef SFX/************************//*  Function version()  *//************************/void version(__G)    __GDEF{    sprintf((char *)slide, LoadFarString(CompiledWith),#if defined(__MWERKS__)      "Metrowerks CodeWarrior", "",#elif defined(__GNUC__)      "GNU C ", __VERSION__,#endif      "BeOS ",#ifdef __POWERPC__      "(PowerPC)",#else# ifdef __INTEL__      "(x86)",# else      "(unknown)",   /* someday we may have other architectures... */# endif#endif#ifdef __DATE__      " on ", __DATE__#else      "", ""#endif    );    (*G.message)((zvoid *)&G, slide, (ulg)strlen((char *)slide), 0);} /* end function version() */#endif /* !SFX *//******************************//* Extra field functions      *//******************************//*** Scan the extra fields in extra_field, and look for a BeOS EF; return a** pointer to that EF, or NULL if it's not there.*/static uch *scanBeOSexfield( const uch *ef_ptr, unsigned ef_len ){    while( ef_ptr != NULL && ef_len >= EB_HEADSIZE ) {        unsigned eb_id  = makeword(EB_ID + ef_ptr);        unsigned eb_len = makeword(EB_LEN + ef_ptr);        if (eb_len > (ef_len - EB_HEADSIZE)) {            Trace((stderr,              "scanBeOSexfield: block length %u > rest ef_size %u\n", eb_len,              ef_len - EB_HEADSIZE));            break;        }        if( eb_id == EF_BEOS && eb_len >= EB_BEOS_HLEN ) {            return (uch *)ef_ptr;        }        ef_ptr += (eb_len + EB_HEADSIZE);        ef_len -= (eb_len + EB_HEADSIZE);    }    return NULL;}/* Used by setBeOSexfield():Set a file/directory's attributes to the attributes passed in.If set_file_attrs() fails, an error will be returned:     EOK - no errors occurred(other values will be whatever the failed function returned; no docsyet, or I'd list a few)*/static int set_file_attrs( const char *name,                           const unsigned char *attr_buff,                           const off_t attr_size ){    int                  retval = EOK;    unsigned char       *ptr;    const unsigned char *guard;    int                  fd;    ptr   = (unsigned char *)attr_buff;    guard = ptr + attr_size;    fd = open( name, O_RDWR | O_NOTRAVERSE );    if( fd < 0 ) {        return errno; /* should it be -fd ? */    }    while( ptr < guard ) {        ssize_t              wrote_bytes;        struct attr_info     fa_info;        const char          *attr_name;        unsigned char       *attr_data;        attr_name  = (char *)&(ptr[0]);        ptr       += strlen( attr_name ) + 1;        /* The attr_info data is stored in big-endian format because the */        /* PowerPC port was here first.                                  */        memcpy( &fa_info, ptr, sizeof( struct attr_info ) );        fa_info.type = (uint32)B_BENDIAN_TO_HOST_INT32( fa_info.type );        fa_info.size = (off_t)B_BENDIAN_TO_HOST_INT64( fa_info.size );        ptr     += sizeof( struct attr_info );        if( fa_info.size < 0LL ) {            Info(slide, 0x201, ((char *)slide,                 "warning: skipping attribute with invalid length (%Ld)\n",                 fa_info.size));            break;        }        attr_data  = ptr;        ptr       += fa_info.size;        if( ptr > guard ) {            /* We've got a truncated attribute. */            Info(slide, 0x201, ((char *)slide,                 "warning: truncated attribute\n"));            break;        }        /* Wave the magic wand... this will swap Be-known types properly. */        (void)swap_data( fa_info.type, attr_data, fa_info.size,                         B_SWAP_BENDIAN_TO_HOST );        wrote_bytes = fs_write_attr( fd, attr_name, fa_info.type, 0,                                     attr_data, fa_info.size );        if( wrote_bytes != fa_info.size ) {            Info(slide, 0x201, ((char *)slide,                 "warning: wrote %ld attribute bytes of %ld\n",                 (unsigned long)wrote_bytes,(unsigned long)fa_info.size));        }    }    close( fd );    return retval;}static void setBeOSexfield( const char *path, uch *extra_field ){    uch *ptr       = extra_field;    ush  id        = 0;    ush  size      = 0;    ulg  full_size = 0;    uch  flags     = 0;    uch *attrbuff  = NULL;    int retval;    if( extra_field == NULL ) {        return;    }    /* Collect the data from the extra field buffer. */    id        = makeword( ptr );    ptr += 2;   /* we don't use this... */    size      = makeword( ptr );    ptr += 2;    full_size = makelong( ptr );    ptr += 4;    flags     = *ptr;               ptr++;    /* Do a little sanity checking. */    if( flags & EB_BE_FL_BADBITS ) {        /* corrupted or unsupported */        Info(slide, 0x201, ((char *)slide,             "Unsupported flags set for this BeOS extra field, skipping.\n"));        return;    }    if( size <= EB_BEOS_HLEN ) {        /* corrupted, unsupported, or truncated */        Info(slide, 0x201, ((char *)slide,             "BeOS extra field is %d bytes, should be at least %d.\n", size,             EB_BEOS_HLEN));        return;    }    if( full_size < ( size - EB_BEOS_HLEN ) ) {        /* possible old archive? will this screw up on valid archives? */        Info(slide, 0x201, ((char *)slide,             "Skipping attributes: BeOS extra field is %d bytes, "             "data size is %ld.\n", size - EB_BEOS_HLEN, full_size));        return;    }    /* Find the BeOS file attribute data. */    if( flags & EB_BE_FL_UNCMPR ) {        /* Uncompressed data */        attrbuff = ptr;    } else {        /* Compressed data */        attrbuff = (uch *)malloc( full_size );        if( attrbuff == NULL ) {            /* No memory to uncompress attributes */            Info(slide, 0x201, ((char *)slide,                 "Can't allocate memory to uncompress file attributes.\n"));            return;        }        retval = memextract( __G__ attrbuff, full_size,                             ptr, size - EB_BEOS_HLEN );        if( retval != PK_OK ) {            /* error uncompressing attributes */            Info(slide, 0x201, ((char *)slide,                 "Error uncompressing file attributes.\n"));            /* Some errors here might not be so bad; we should expect */            /* some truncated data, for example.  If the data was     */            /* corrupt, we should _not_ attempt to restore the attrs  */            /* for this file... there's no way to detect what attrs   */            /* are good and which are bad.                            */            free( attrbuff );            return;        }    }    /* Now attempt to set the file attributes on the extracted file. */    retval = set_file_attrs( path, attrbuff, (off_t)full_size );    if( retval != EOK ) {        Info(slide, 0x201, ((char *)slide,             "Error writing file attributes.\n"));    }    /* Clean up, if necessary */    if( attrbuff != ptr ) {        free( attrbuff );    }    return;}static void printBeOSexfield( int isdir, uch *extra_field ){    uch *ptr       = extra_field;    ush  id        = 0;    ush  size      = 0;    ulg  full_size = 0;    uch  flags     = 0;    /* Tell picky compilers to be quiet. */    isdir = isdir;    if( extra_field == NULL ) {        return;    }    /* Collect the data from the buffer. */    id        = makeword( ptr );    ptr += 2;    size      = makeword( ptr );    ptr += 2;    full_size = makelong( ptr );    ptr += 4;    flags     = *ptr;               ptr++;    if( id != EF_BEOS ) {        /* not a 'Be' field */        printf("\t*** Unknown field type (0x%04x, '%c%c')\n", id,               (char)(id >> 8), (char)id);    }    if( flags & EB_BE_FL_BADBITS ) {        /* corrupted or unsupported */        printf("\t*** Corrupted BeOS extra field:\n");        printf("\t*** unknown bits set in the flags\n");        printf("\t*** (Possibly created by an old version of zip for BeOS.\n");    }    if( size <= EB_BEOS_HLEN ) {        /* corrupted, unsupported, or truncated */        printf("\t*** Corrupted BeOS extra field:\n");        printf("\t*** size is %d, should be larger than %d\n", size,               EB_BEOS_HLEN );    }    if( flags & EB_BE_FL_UNCMPR ) {        /* Uncompressed data */        printf("\tBeOS extra field data (uncompressed):\n");        printf("\t\t%ld data bytes\n", full_size);    } else {        /* Compressed data */        printf("\tBeOS extra field data (compressed):\n");        printf("\t\t%d compressed bytes\n", size - EB_BEOS_HLEN);        printf("\t\t%ld uncompressed bytes\n", full_size);    }}#ifdef BEOS_ASSIGN_FILETYPE/* Note: This will no longer be necessary in BeOS PR4; update_mime_info()    *//* will be updated to build its own absolute pathname if it's not given one. */static void assign_MIME( const char *file ){    char *fullname;    char buff[PATH_MAX], cwd_buff[PATH_MAX];    int retval;    if( file[0] == '/' ) {        fullname = (char *)file;    } else {        sprintf( buff, "%s/%s", getcwd( cwd_buff, PATH_MAX ), file );        fullname = buff;    }    retval = update_mime_info( fullname, FALSE, TRUE, TRUE );}#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -