Annotation of coherent/b/lib/libc/gen/coffnlist.c, revision 1.1.1.1

1.1       root        1: /*
                      2:  * libc/gen/coffnlist.c
                      3:  * Get entries from coff nlist.
                      4:  */
                      5: 
                      6: #include <stdio.h>
                      7: #include <coff.h>
                      8: 
                      9: /*
                     10:  * Symbol name.
                     11:  */
                     12: static char *
                     13: symName(sym, str_tab, work)
                     14: SYMENT *sym;
                     15: char *str_tab, *work;
                     16: {
                     17:        if (!sym->n_zeroes)
                     18:                return (str_tab + sym->n_offset - 4);
                     19: 
                     20:        /* make sure it's zero terminated */
                     21:        memcpy(work, sym->n_name, SYMNMLEN);
                     22:        work[SYMNMLEN] = '\0';
                     23:        return (work);
                     24: }
                     25: 
                     26: coffnlist(fn, nlp, names, count)
                     27: char *fn;      /* file name */
                     28: SYMENT *nlp;   /* names to look up */
                     29: char *names;   /* long names */
                     30: int count;     /* size of passed table */
                     31: {
                     32:        FILEHDR head;
                     33:        FILE *fp;
                     34:        char *str_tab;
                     35:        long str_length;
                     36:        int aux, i;
                     37: 
                     38:        if (NULL == (fp = fopen(fn, "rb")))
                     39:                return(0);
                     40: 
                     41:        if (1 != fread(&head, sizeof(head), 1, fp) ||
                     42:            head.f_magic != C_386_MAGIC) {
                     43:                fclose (fp);
                     44:                return (0);
                     45:        }
                     46: 
                     47:        fseek(fp, head.f_symptr + (SYMESZ * head.f_nsyms), 0);
                     48:        if (1 != fread(&str_length, sizeof(str_length), 1, fp))
                     49:                str_length = 0;
                     50:        if (str_length) {
                     51:                unsigned len;
                     52: 
                     53:                len = str_length -= 4;
                     54:                if (len != str_length || NULL == (str_tab = malloc(len))) {
                     55:                        fclose (fp);
                     56:                        return (0);
                     57:                }
                     58: 
                     59:                if (1 != fread(str_tab, len, 1, fp)) {
                     60:                        free(str_tab);
                     61:                        fclose (fp);
                     62:                        return (0);
                     63:                }
                     64:        }
                     65: 
                     66:        fseek(fp, head.f_symptr, 0);
                     67:        for (i = aux = 0; i < head.f_nsyms; i++) {
                     68:                SYMENT sym;     /* symbol read in */
                     69:                int taux, j;
                     70: 
                     71:                if (1 != fread(&sym, SYMESZ, 1, fp)) {
                     72:                        free(str_tab);
                     73:                        fclose (fp);
                     74:                        return (0);
                     75:                }
                     76:                if (aux) {
                     77:                        aux--;
                     78:                        continue;
                     79:                }
                     80:                aux = sym.n_numaux;
                     81:                for (j = taux = 0; j < count; j++) {
                     82:                        static char n1[SYMNMLEN + 1], n2[SYMNMLEN + 1];
                     83:                        register SYMENT *np;
                     84: 
                     85:                        if (taux) {
                     86:                                taux--;
                     87:                                continue;
                     88:                        }
                     89:                        np = nlp + j;
                     90:                        taux = np->n_numaux;
                     91:                        if (np->n_type != 0xFFFF ||
                     92:                            strcmp(symName(np, names, n1),
                     93:                                   symName(&sym, str_tab, n2)))
                     94:                                continue;
                     95:                        np->n_value  = sym.n_value;
                     96:                        np->n_scnum  = sym.n_scnum;
                     97:                        np->n_type   = sym.n_type;
                     98:                        np->n_sclass = sym.n_sclass;
                     99:                }
                    100:        }
                    101:        free(str_tab);
                    102:        fclose (fp);
                    103:        return (1);
                    104: }
                    105: 
                    106: #ifdef TEST
                    107: main()
                    108: {
                    109:        static SYMENT sym[3];
                    110:        static char ptr[] = "a_very_long_name";
                    111: 
                    112:        strcpy(sym[0]._n._n_name, "x");
                    113:        sym[0].n_type = -1;
                    114: 
                    115:        strcpy(sym[1]._n._n_name, "y");
                    116:        sym[1].n_type = -1;
                    117: 
                    118:        sym[2]._n._n_n._n_zeroes = 0;
                    119:        sym[2]._n._n_n._n_offset = sizeof(long);
                    120:        sym[2].n_type = -1;
                    121: 
                    122:        coffnlist("tx.o", sym, ptr, 3);
                    123: }
                    124: #endif
                    125: 
                    126: /* end of coffnlist.c */

unix.superglobalmegacorp.com

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