Annotation of Net2/kern/kern_subr.c, revision 1.1.1.4

1.1       root        1: /*
                      2:  * Copyright (c) 1982, 1986, 1991 Regents of the University of California.
                      3:  * All rights reserved. 
                      4:  *
                      5:  * Redistribution and use in source and binary forms, with or without
                      6:  * modification, are permitted provided that the following conditions
                      7:  * are met:
                      8:  * 1. Redistributions of source code must retain the above copyright
                      9:  *    notice, this list of conditions and the following disclaimer.
                     10:  * 2. Redistributions in binary form must reproduce the above copyright
                     11:  *    notice, this list of conditions and the following disclaimer in the
                     12:  *    documentation and/or other materials provided with the distribution.
                     13:  * 3. All advertising materials mentioning features or use of this software
                     14:  *    must display the following acknowledgement:
                     15:  *     This product includes software developed by the University of
                     16:  *     California, Berkeley and its contributors.
                     17:  * 4. Neither the name of the University nor the names of its contributors
                     18:  *    may be used to endorse or promote products derived from this software
                     19:  *    without specific prior written permission.
                     20:  *
                     21:  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
                     22:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     23:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     24:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
                     25:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     26:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                     27:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     28:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     29:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     30:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     31:  * SUCH DAMAGE.
                     32:  *
                     33:  *     @(#)kern_subr.c 7.7 (Berkeley) 4/15/91
1.1.1.4 ! root       34:  *
        !            35:  * PATCHES MAGIC                LEVEL   PATCH THAT GOT US HERE
        !            36:  * --------------------         -----   ----------------------
        !            37:  * CURRENT PATCH LEVEL:         1       00081
        !            38:  * --------------------         -----   ----------------------
        !            39:  *
        !            40:  * 07 Feb 93   Julian Elischer         Moverd strcmp here where it belongs
1.1       root       41:  */
1.1.1.2   root       42: static char rcsid[] = "$Header: /usr/bill/working/sys/kern/RCS/kern_subr.c,v 1.3 92/01/21 21:29:28 william Exp $";
1.1       root       43: 
                     44: #include "param.h"
                     45: #include "systm.h"
                     46: #include "proc.h"
                     47: 
                     48: uiomove(cp, n, uio)
                     49:        register caddr_t cp;
                     50:        register int n;
                     51:        register struct uio *uio;
                     52: {
                     53:        register struct iovec *iov;
                     54:        u_int cnt;
                     55:        int error = 0;
                     56: 
                     57: 
                     58: #ifdef DIAGNOSTIC
                     59:        if (uio->uio_rw != UIO_READ && uio->uio_rw != UIO_WRITE)
                     60:                panic("uiomove: mode");
                     61:        if (uio->uio_segflg == UIO_USERSPACE && uio->uio_procp != curproc)
                     62:                panic("uiomove proc");
                     63: #endif
                     64:        while (n > 0 && uio->uio_resid) {
                     65:                iov = uio->uio_iov;
                     66:                cnt = iov->iov_len;
                     67:                if (cnt == 0) {
                     68:                        uio->uio_iov++;
                     69:                        uio->uio_iovcnt--;
                     70:                        continue;
                     71:                }
                     72:                if (cnt > n)
                     73:                        cnt = n;
                     74:                switch (uio->uio_segflg) {
                     75: 
                     76:                case UIO_USERSPACE:
                     77:                case UIO_USERISPACE:
                     78:                        if (uio->uio_rw == UIO_READ)
                     79:                                error = copyout(cp, iov->iov_base, cnt);
                     80:                        else
                     81:                                error = copyin(iov->iov_base, cp, cnt);
                     82:                        if (error)
                     83:                                return (error);
                     84:                        break;
                     85: 
                     86:                case UIO_SYSSPACE:
                     87:                        if (uio->uio_rw == UIO_READ)
                     88:                                bcopy((caddr_t)cp, iov->iov_base, cnt);
                     89:                        else
                     90:                                bcopy(iov->iov_base, (caddr_t)cp, cnt);
                     91:                        break;
                     92:                }
                     93:                iov->iov_base += cnt;
                     94:                iov->iov_len -= cnt;
                     95:                uio->uio_resid -= cnt;
                     96:                uio->uio_offset += cnt;
                     97:                cp += cnt;
                     98:                n -= cnt;
                     99:        }
                    100:        return (error);
                    101: }
                    102: 
1.1.1.2   root      103: uioapply(func, arg1, arg2, uio)
                    104:        int (*func)() ;
                    105:        register struct uio *uio;
                    106: {
                    107:        register struct iovec *iov;
                    108:        u_int cnt, cnt1;
                    109:        int error = 0;
                    110: 
                    111: 
                    112: /*#ifdef DIAGNOSTIC*/
                    113:        if (uio->uio_rw != UIO_READ && uio->uio_rw != UIO_WRITE)
                    114:                panic("uioapply: mode");
                    115:        if (uio->uio_segflg == UIO_USERSPACE && uio->uio_procp != curproc)
                    116:                panic("uioapply proc");
                    117: /*#endif*/
                    118:        while (uio->uio_resid) {
                    119:                iov = uio->uio_iov;
                    120:                cnt = iov->iov_len;
                    121:                if (cnt == 0) {
                    122:                        uio->uio_iov++;
                    123:                        uio->uio_iovcnt--;
                    124:                        continue;
                    125:                }
                    126:                cnt1 = cnt;
                    127:                error = (*func)(arg1, arg2, uio->uio_offset, uio->uio_rw,
                    128:                        iov->iov_base, &cnt1, uio->uio_procp);
                    129:                cnt -= cnt1;
                    130:                iov->iov_base += cnt;
                    131:                iov->iov_len -= cnt;
                    132:                uio->uio_resid -= cnt;
                    133:                uio->uio_offset += cnt;
                    134:                if (error || cnt1)
                    135:                        return (error);
                    136:        }
                    137:        return (0);
                    138: }
                    139: 
1.1       root      140: /*
                    141:  * Give next character to user as result of read.
                    142:  */
                    143: ureadc(c, uio)
                    144:        register int c;
                    145:        register struct uio *uio;
                    146: {
                    147:        register struct iovec *iov;
                    148: 
                    149: again:
                    150:        if (uio->uio_iovcnt == 0)
                    151:                panic("ureadc");
                    152:        iov = uio->uio_iov;
                    153:        if (iov->iov_len <= 0 || uio->uio_resid <= 0) {
                    154:                uio->uio_iovcnt--;
                    155:                uio->uio_iov++;
                    156:                goto again;
                    157:        }
                    158:        switch (uio->uio_segflg) {
                    159: 
                    160:        case UIO_USERSPACE:
                    161:                if (subyte(iov->iov_base, c) < 0)
                    162:                        return (EFAULT);
                    163:                break;
                    164: 
                    165:        case UIO_SYSSPACE:
                    166:                *iov->iov_base = c;
                    167:                break;
                    168: 
                    169:        case UIO_USERISPACE:
                    170:                if (suibyte(iov->iov_base, c) < 0)
                    171:                        return (EFAULT);
                    172:                break;
                    173:        }
                    174:        iov->iov_base++;
                    175:        iov->iov_len--;
                    176:        uio->uio_resid--;
                    177:        uio->uio_offset++;
                    178:        return (0);
                    179: }
                    180: 
                    181: strcat(src, append)
                    182:        register char *src, *append;
                    183: {
                    184: 
                    185:        for (; *src; ++src)
                    186:                ;
                    187:        while (*src++ = *append++)
                    188:                ;
                    189: }
                    190: 
                    191: strcpy(to, from)
                    192:        register char *to, *from;
                    193: {
                    194: 
1.1.1.3   root      195:        for (; *to = *from; ++from, ++to)
1.1       root      196:                ;
                    197: }
                    198: 
                    199: strncpy(to, from, cnt)
                    200:        register char *to, *from;
                    201:        register int cnt;
                    202: {
                    203: 
                    204:        for (; cnt && (*to = *from); --cnt, ++from, ++to)
                    205:                ;
                    206:        *to = '\0';
                    207: }
                    208: 
1.1.1.4 ! root      209: 
        !           210: int
        !           211: strcmp(s1, s2)
        !           212:        register const char *s1, *s2;
        !           213: {
        !           214:        while (*s1 == *s2++)
        !           215:                if (*s1++ == 0)
        !           216:                        return (0);
        !           217:        return (*(unsigned char *)s1 - *(unsigned char *)--s2);
        !           218: }
        !           219: 
        !           220:                
        !           221: 
        !           222:        
        !           223: 
        !           224: 
1.1       root      225: #ifndef lint   /* unused except by ct.c, other oddities XXX */
                    226: /*
                    227:  * Get next character written in by user from uio.
                    228:  */
                    229: uwritec(uio)
                    230:        struct uio *uio;
                    231: {
                    232:        register struct iovec *iov;
                    233:        register int c;
                    234: 
                    235:        if (uio->uio_resid <= 0)
                    236:                return (-1);
                    237: again:
                    238:        if (uio->uio_iovcnt <= 0)
                    239:                panic("uwritec");
                    240:        iov = uio->uio_iov;
                    241:        if (iov->iov_len == 0) {
                    242:                uio->uio_iov++;
                    243:                if (--uio->uio_iovcnt == 0)
                    244:                        return (-1);
                    245:                goto again;
                    246:        }
                    247:        switch (uio->uio_segflg) {
                    248: 
                    249:        case UIO_USERSPACE:
                    250:                c = fubyte(iov->iov_base);
                    251:                break;
                    252: 
                    253:        case UIO_SYSSPACE:
                    254:                c = *(u_char *) iov->iov_base;
                    255:                break;
                    256: 
                    257:        case UIO_USERISPACE:
                    258:                c = fuibyte(iov->iov_base);
                    259:                break;
                    260:        }
                    261:        if (c < 0)
                    262:                return (-1);
                    263:        iov->iov_base++;
                    264:        iov->iov_len--;
                    265:        uio->uio_resid--;
                    266:        uio->uio_offset++;
                    267:        return (c);
                    268: }
                    269: #endif /* notdef */

unix.superglobalmegacorp.com

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