]> git.ipfire.org Git - thirdparty/man-pages.git/blobdiff - man3/posix_memalign.3
execve.2, setfsgid.2, setfsuid.2, splice.2, fopen.3, malloc_trim.3, posix_memalign...
[thirdparty/man-pages.git] / man3 / posix_memalign.3
index 50b9a7dc5cf2bb1cce06acc99bc3731bea69551b..7671ed8d0d7520473afefaeab09a9bde43571c91 100644 (file)
 .\" 2001-10-11, 2003-08-22, aeb, added some details
 .\" 2012-03-23, Michael Kerrisk <mtk.manpages@mail.com>
 .\"     Document pvalloc() and aligned_alloc()
-.TH POSIX_MEMALIGN 3  2012-03-23 "GNU" "Linux Programmer's Manual"
+.TH POSIX_MEMALIGN 3  2019-05-09 "GNU" "Linux Programmer's Manual"
 .SH NAME
 posix_memalign, aligned_alloc, memalign, valloc, pvalloc \- allocate aligned memory
 .SH SYNOPSIS
 .nf
 .B #include <stdlib.h>
-.sp
+.PP
 .BI "int posix_memalign(void **" memptr ", size_t " alignment ", size_t " size );
 .BI "void *aligned_alloc(size_t " alignment ", size_t " size );
 .BI "void *valloc(size_t " size );
-.sp
+
 .B #include <malloc.h>
-.sp
+.PP
 .BI "void *memalign(size_t " alignment ", size_t " size );
 .BI "void *pvalloc(size_t " size );
 .fi
-.sp
+.PP
 .in -4n
 Feature Test Macro Requirements for glibc (see
 .BR feature_test_macros (7)):
 .in
-.sp
+.PP
 .ad l
 .BR posix_memalign ():
-_POSIX_C_SOURCE\ >=\ 200112L || _XOPEN_SOURCE\ >=\ 600
-.sp
+_POSIX_C_SOURCE\ >=\ 200112L
+.PP
 .BR aligned_alloc ():
 _ISOC11_SOURCE
-.sp
+.PP
 .BR valloc ():
 .br
 .PD 0
@@ -62,16 +62,15 @@ _ISOC11_SOURCE
 .TP 4
 Since glibc 2.12:
 .nf
-_BSD_SOURCE ||
-    (_XOPEN_SOURCE\ >=\ 500 ||
-        _XOPEN_SOURCE\ &&\ _XOPEN_SOURCE_EXTENDED) &&
-    !(_POSIX_C_SOURCE\ >=\ 200112L || _XOPEN_SOURCE\ >=\ 600)
+(_XOPEN_SOURCE\ >=\ 500) && !(_POSIX_C_SOURCE\ >=\ 200112L)
+    || /* Glibc since 2.19: */ _DEFAULT_SOURCE
+    || /* Glibc versions <= 2.19: */ _SVID_SOURCE || _BSD_SOURCE
 .br
 .fi
 .TP
 Before glibc 2.12:
-_BSD_SOURCE || _XOPEN_SOURCE\ >=\ 500 ||
-_XOPEN_SOURCE\ &&\ _XOPEN_SOURCE_EXTENDED
+_BSD_SOURCE || _XOPEN_SOURCE\ >=\ 500
+.\"    || _XOPEN_SOURCE\ &&\ _XOPEN_SOURCE_EXTENDED
 .ad b
 .br
 (The (nonstandard) header file
@@ -91,16 +90,17 @@ bytes and places the address of the allocated memory in
 The address of the allocated memory will be a multiple of
 .IR "alignment" ,
 which must be a power of two and a multiple of
-.IR "sizeof(void *)".
+.IR "sizeof(void\ *)" .
 If
 .I size
 is 0, then
-.BR posix_memalign ()
-returns either NULL,
+the value placed in
+.IR "*memptr"
+is either NULL,
 .\" glibc does this:
 or a unique pointer value that can later be successfully passed to
 .BR free (3).
-
+.PP
 The obsolete function
 .BR memalign ()
 allocates
@@ -111,7 +111,7 @@ The memory address will be a multiple of
 which must be a power of two.
 .\" The behavior of memalign() for size==0 is as for posix_memalign()
 .\" but no standards govern this.
-
+.PP
 The function
 .BR aligned_alloc ()
 is the same as
@@ -120,7 +120,7 @@ except for the added restriction that
 .I size
 should be a multiple of
 .IR alignment .
-
+.PP
 The obsolete function
 .BR valloc ()
 allocates
@@ -129,14 +129,14 @@ bytes and returns a pointer to the allocated memory.
 The memory address will be a multiple of the page size.
 It is equivalent to
 .IR "memalign(sysconf(_SC_PAGESIZE),size)" .
-
+.PP
 The obsolete function
 .BR pvalloc ()
 is similar to
 .BR valloc (),
 but rounds the size of the allocation up to
 the next multiple of the system page size.
-
+.PP
 For all of these functions, the memory is not zeroed.
 .SH RETURN VALUE
 .BR aligned_alloc (),
@@ -144,21 +144,30 @@ For all of these functions, the memory is not zeroed.
 .BR valloc (),
 and
 .BR pvalloc ()
-return a pointer to the allocated memory, or NULL if the request fails.
-
+return a pointer to the allocated memory on success.
+On error, NULL is returned, and \fIerrno\fP is set
+to indicate the cause of the error.
+.PP
 .BR posix_memalign ()
 returns zero on success, or one of the error values listed in the
 next section on failure.
-Note that
+The value of
 .I errno
 is not set.
+On Linux (and other systems),
+.BR posix_memalign ()
+does not modify
+.I memptr
+on failure.
+A requirement standardizing this behavior was added in POSIX.1-2016.
+.\" http://austingroupbugs.net/view.php?id=520
 .SH ERRORS
 .TP
 .B EINVAL
 The
 .I alignment
 argument was not a power of two, or was not a multiple of
-.IR "sizeof(void *)" .
+.IR "sizeof(void\ *)" .
 .TP
 .B ENOMEM
 There was insufficient memory to fulfill the allocation request.
@@ -169,34 +178,56 @@ The functions
 and
 .BR pvalloc ()
 have been available in all Linux libc libraries.
-
+.PP
 The function
 .BR aligned_alloc ()
 was added to glibc in version 2.16.
-
+.PP
 The function
 .BR posix_memalign ()
 is available since glibc 2.1.91.
+.SH ATTRIBUTES
+For an explanation of the terms used in this section, see
+.BR attributes (7).
+.TS
+allbox;
+lb lb lb
+l l l.
+Interface      Attribute       Value
+T{
+.BR aligned_alloc (),
+.br
+.BR memalign (),
+.br
+.BR posix_memalign ()
+T}     Thread safety   MT-Safe
+T{
+.BR valloc (),
+.br
+.BR pvalloc ()
+T}     Thread safety   MT-Unsafe init
+.TE
+.sp 1
 .SH CONFORMING TO
 The function
 .BR valloc ()
 appeared in 3.0BSD.
 It is documented as being obsolete in 4.3BSD,
 and as legacy in SUSv2.
-It does not appear in POSIX.1-2001.
-
+It does not appear in POSIX.1.
+.PP
 The function
 .BR pvalloc ()
 is a GNU extension.
-
+.PP
 The function
 .BR memalign ()
 appears in SunOS 4.1.3 but not in 4.4BSD.
-
+.PP
 The function
 .BR posix_memalign ()
-comes from POSIX.1d.
-
+comes from POSIX.1d and is specified in POSIX.1-2001 and POSIX.1-2008.
+.PP
 The function
 .BR aligned_alloc ()
 is specified in the C11 standard.
@@ -205,11 +236,11 @@ is specified in the C11 standard.
 Everybody agrees that
 .BR posix_memalign ()
 is declared in \fI<stdlib.h>\fP.
-
+.PP
 On some systems
 .BR memalign ()
 is declared in \fI<stdlib.h>\fP instead of \fI<malloc.h>\fP.
-
+.PP
 According to SUSv2,
 .BR valloc ()
 is declared in \fI<stdlib.h>\fP.
@@ -225,7 +256,7 @@ call that tells what alignment is needed.
 Now one can use
 .BR posix_memalign ()
 to satisfy this requirement.
-
+.PP
 .BR posix_memalign ()
 verifies that
 .I alignment
@@ -234,7 +265,7 @@ matches the requirements detailed above.
 may not check that the
 .I alignment
 argument is correct.
-
+.PP
 POSIX requires that memory obtained from
 .BR posix_memalign ()
 can be freed using
@@ -243,9 +274,9 @@ Some systems provide no way to reclaim memory allocated with
 .BR memalign ()
 or
 .BR valloc ()
-(because one can only pass to
+(because one can pass to
 .BR free (3)
-a pointer gotten from
+only a pointer obtained from
 .BR malloc (3),
 while, for example,
 .BR memalign ()
@@ -262,11 +293,11 @@ The glibc implementation
 allows memory obtained from any of these functions to be
 reclaimed with
 .BR free (3).
-
+.PP
 The glibc
 .BR malloc (3)
-always returns 8-byte aligned memory addresses, so these functions are only
-needed if you require larger alignment values.
+always returns 8-byte aligned memory addresses, so these functions are
+needed only if you require larger alignment values.
 .SH SEE ALSO
 .BR brk (2),
 .BR getpagesize (2),