Annotation of coherent/b/bin/ipcs/pick_nfile.c, revision 1.1

1.1     ! root        1: #define KERNEL
        !             2: #include <sys/typed.h>
        !             3: #undef KERNEL
        !             4: #include <fcntl.h>
        !             5: 
        !             6: #ifndef T_NULL
        !             7: #define T_NULL ((char *)0)
        !             8: #endif
        !             9: 
        !            10: /*
        !            11:  * Pick a namelist file.
        !            12:  *
        !            13:  * If we can't open /dev/boot_gift, guess "/coherent".
        !            14:  * If boot_gift does not have a command line, guess "/autoboot".
        !            15:  * Otherwise, pull the boot file from the command line.
        !            16:  */
        !            17: char *
        !            18: pick_nfile()
        !            19: {
        !            20:        int fd;
        !            21:        FIFO *ffp;
        !            22:        typed_space *tp;
        !            23:        int found;
        !            24:        TYPED_SPACE(boot_gift, BG_LEN, T_FIFO_SIC);
        !            25: 
        !            26:        /* 16 characters are for "/", a 14 character name, and a NUL.  */
        !            27:        static char retval[16];
        !            28: 
        !            29:        if (-1 == (fd = open("/dev/boot_gift", O_RDONLY))) {
        !            30:                /* Can't open boot_gift, guess "/coherent".  */
        !            31:                strcpy(retval, "/coherent");
        !            32:                return(retval);
        !            33:        }
        !            34:        
        !            35:        if (0 == read(fd, &boot_gift, BG_LEN)) {
        !            36:                close(fd);
        !            37:                /* Can't read boot_gift, guess "/coherent".  */
        !            38:                strcpy(retval, "/coherent");
        !            39:                return(retval);
        !            40:        }
        !            41: 
        !            42:        close(fd);
        !            43: 
        !            44:        found = 0; /* We are looking for the command line.  */
        !            45:        if (F_NULL != (ffp = fifo_open(&boot_gift, 0))) {
        !            46:                for (; !found && T_NULL != (tp = fifo_read(ffp)); ) {
        !            47:                        if (T_STR_ARGF == tp->ts_type) {
        !            48:                                found = 1;
        !            49:                                break;
        !            50:                        }
        !            51:                }
        !            52:                fifo_close(ffp);
        !            53: 
        !            54:                if (!found) {
        !            55:                        strcpy(retval, "/autoboot");
        !            56:                } else {
        !            57:                        /* Recast the argument list, so we can read it.  */
        !            58:                        RETYPE(tp, T_FIFO_SIC);
        !            59:                        ffp = fifo_open(tp, 0);
        !            60:                        if (T_NULL == (tp = fifo_read(ffp))) {
        !            61:                                strcpy(retval, "/autoboot");
        !            62:                        } else {
        !            63:                                sprintf(retval, "/%.14s", tp->ts_data);
        !            64:                        }
        !            65:                        fifo_close(ffp);
        !            66:                }
        !            67:        } else {
        !            68:                strcpy(retval, "/autoboot");
        !            69:        }
        !            70: 
        !            71:        return(retval);
        !            72: 
        !            73: } /* pick_nfile() */
        !            74: 

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.