Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 148351
Collapse All | Expand All

(-)include.orig/stdlib.h (-1 / +1 lines)
Lines 157-163 Link Here
157
 * research can be done.
157
 * research can be done.
158
 */
158
 */
159
#if __POSIX_VISIBLE /* >= ??? */
159
#if __POSIX_VISIBLE /* >= ??? */
160
/* int  posix_memalign(void **, size_t, size_t); (ADV) */
160
int     posix_memalign(void **, size_t, size_t); /* (ADV) */
161
int     rand_r(unsigned *);                    /* (TSF) */
161
int     rand_r(unsigned *);                    /* (TSF) */
162
int     setenv(const char *, const char *, int);
162
int     setenv(const char *, const char *, int);
163
void    unsetenv(const char *);
163
void    unsetenv(const char *);
(-)lib.orig/libc/stdlib/Makefile.inc (-1 / +1 lines)
Lines 44-48 Link Here
44
MLINKS+=strtol.3 strtoll.3 strtol.3 strtoq.3 strtol.3 strtoimax.3
44
MLINKS+=strtol.3 strtoll.3 strtol.3 strtoq.3 strtol.3 strtoimax.3
45
MLINKS+=strtoul.3 strtoull.3 strtoul.3 strtouq.3 strtoul.3 strtoumax.3
45
MLINKS+=strtoul.3 strtoull.3 strtoul.3 strtouq.3 strtoul.3 strtoumax.3
46
MLINKS+=malloc.3 calloc.3 malloc.3 free.3 malloc.3 malloc.conf.5 \
46
MLINKS+=malloc.3 calloc.3 malloc.3 free.3 malloc.3 malloc.conf.5 \
47
       malloc.3 realloc.3 malloc.3 reallocf.3
47
       malloc.3 realloc.3 malloc.3 reallocf.3 malloc.3 posix_memalign.3
48
MLINKS+=tsearch.3 tdelete.3 tsearch.3 tfind.3 tsearch.3 twalk.3
48
MLINKS+=tsearch.3 tdelete.3 tsearch.3 tfind.3 tsearch.3 twalk.3
(-)lib.orig/libc/stdlib/malloc.3 (-3 / +46 lines)
Lines 36-46 Link Here
36
.\"     @(#)malloc.3   8.1 (Berkeley) 6/4/93
36
.\"     @(#)malloc.3   8.1 (Berkeley) 6/4/93
37
.\" $FreeBSD: src/lib/libc/stdlib/malloc.3,v 1.63 2005/01/20 09:17:04 ru Exp $
37
.\" $FreeBSD: src/lib/libc/stdlib/malloc.3,v 1.63 2005/01/20 09:17:04 ru Exp $
38
.\"
38
.\"
39
.Dd August 19, 2004
39
.Dd October 16, 2005
40
.Dt MALLOC 3
40
.Dt MALLOC 3
41
.Os
41
.Os
42
.Sh NAME
42
.Sh NAME
43
.Nm malloc , calloc , realloc , free , reallocf
43
.Nm malloc , calloc , realloc , free , reallocf , posix_memalign
44
.Nd general purpose memory allocation functions
44
.Nd general purpose memory allocation functions
45
.Sh LIBRARY
45
.Sh LIBRARY
46
.Lb libc
46
.Lb libc
Lines 54-59 Link Here
54
.Fn realloc "void *ptr" "size_t size"
54
.Fn realloc "void *ptr" "size_t size"
55
.Ft void *
55
.Ft void *
56
.Fn reallocf "void *ptr" "size_t size"
56
.Fn reallocf "void *ptr" "size_t size"
57
.Ft int
58
.Fn posix_memalign "void **ptr" "size_t alignment" "size_t size"
57
.Ft void
59
.Ft void
58
.Fn free "void *ptr"
60
.Fn free "void *ptr"
59
.Ft const char *
61
.Ft const char *
Lines 148-153 Link Here
148
for realloc causing memory leaks in libraries.
150
for realloc causing memory leaks in libraries.
149
.Pp
151
.Pp
150
The
152
The
153
.Fn posix_memalign
154
function allocates
155
.Fa size
156
bytes aligned on a boundary specified by
157
.Fa alignment
158
and places the address of the allocated memory in
159
.Fa ptr .
160
The value of
161
.Fa alignment
162
must be a power of two and a multiple of
163
.Fn sizeof "void *" .
164
.Pp
165
The
151
.Fn free
166
.Fn free
152
function causes the allocated memory referenced by
167
function causes the allocated memory referenced by
153
.Fa ptr
168
.Fa ptr
Lines 276-281 Link Here
276
.Er ENOMEM .
291
.Er ENOMEM .
277
.Pp
292
.Pp
278
The
293
The
294
.Fn posix_memalign
295
function returns zero on success,
296
.Er EINVAL
297
if the
298
.Fa alignment
299
parameter was not a power of two, or was not a multiple of
300
.Fn sizeof "void *" .
301
Note that
302
.Va errno
303
is not set.
304
.Pp
305
The
279
.Fn realloc
306
.Fn realloc
280
and
307
and
281
.Fn reallocf
308
.Fn reallocf
Lines 363-369 Link Here
363
If
390
If
364
.Fn malloc ,
391
.Fn malloc ,
365
.Fn calloc ,
392
.Fn calloc ,
366
.Fn realloc
393
.Fn realloc ,
394
.Fn posix_memalign
367
or
395
or
368
.Fn free
396
.Fn free
369
detect an error or warning condition,
397
detect an error or warning condition,
Lines 480-485 Link Here
480
.Fn free
508
.Fn free
481
functions conform to
509
functions conform to
482
.St -isoC .
510
.St -isoC .
511
.Pp
512
The
513
.Fn posix_memalign
514
function conforms to
515
.St -p1003.1-2001 .
483
.Sh HISTORY
516
.Sh HISTORY
484
The present allocation implementation started out as a file system for a
517
The present allocation implementation started out as a file system for a
485
drum attached to a 20bit binary challenged computer which was built
518
drum attached to a 20bit binary challenged computer which was built
Lines 493-500 Link Here
493
.Fn reallocf
526
.Fn reallocf
494
function first appeared in
527
function first appeared in
495
.Fx 3.0 .
528
.Fx 3.0 .
529
.Pp
530
The
531
.Fn posix_memalign
532
function first appeared in
533
.Fx 7.0 .
496
.Sh AUTHORS
534
.Sh AUTHORS
497
.An Poul-Henning Kamp Aq phk@FreeBSD.org
535
.An Poul-Henning Kamp Aq phk@FreeBSD.org
536
.Pp
537
The
538
.Fn posix_memalign
539
function was added by
540
.An Sergey Matveychuk Aq sem@FreeBSD.org
498
.Sh BUGS
541
.Sh BUGS
499
The messages printed in case of problems provide no detail about the
542
The messages printed in case of problems provide no detail about the
500
actual values.
543
actual values.
(-)lib.orig/libc/stdlib/malloc.c (+22 lines)
Lines 1164-1166 Link Here
1164
    return (pubrealloc(ptr, size, " in realloc():"));
1164
    return (pubrealloc(ptr, size, " in realloc():"));
1165
}
1165
}
1166
#define POWEROF2(x) ((((x)-1)&(x))==0)
1167
1168
int
1169
posix_memalign(void **ptr, size_t alignment, size_t size)
1170
{
1171
    void *p1;
1172
    int err;
1173
1174
    if (alignment % sizeof(void *) || !POWEROF2(alignment))
1175
       return(EINVAL);
1176
1177
    p1 = pubrealloc(NULL, (size+alignment-1) & ~(alignment-1),
1178
           " in posix_memalign():");
1179
    if(p1) {
1180
       *ptr = p1;
1181
       return (0);
1182
    } else {
1183
       err = errno;
1184
       errno = 0;
1185
       return (err);
1186
    }
1187
}

Return to bug 148351