📄 t_alloc.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"><html><head><!-- Copyright 1997 The Open Group, All Rights Reserved --><title>t_alloc</title></head><body bgcolor=white><center><font size=2>The Single UNIX ® Specification, Version 2<br>Copyright © 1997 The Open Group</font></center><hr size=2 noshade><h4>NAME</h4><blockquote>t_alloc - allocate a library structure</blockquote><h4>SYNOPSIS</h4><blockquote><pre><code>#include <<a href="xti.h.html">xti.h</a>>void *t_alloc( int fd, int struct_type, int fields)</code></pre></blockquote><h4>DESCRIPTION</h4><blockquote><pre><P><table bordercolor=#000000 border=1 align=center><tr valign=top><th align=center><b>Parameters</b><th align=center><b>Before call</b><th align=center><b>After call</b><tr valign=top><td align=left>fd<td align=center>x<td align=center>/<tr valign=top><td align=left>struct_type<td align=center>x<td align=center>/<tr valign=top><td align=left>fields<td align=center>x<td align=center>/</table></pre><p>The<i>t_alloc()</i>function dynamically allocates memory for thevarious transport function argument structures as specified below.This function will allocate memory for the specified structure, andwill also allocate memory for buffers referenced by the structure.<p>The structure to allocate is specified by<I>struct_type</I>and must be one of the following:<pre><code>T_BIND struct t_bindT_CALL struct t_callT_OPTMGMT struct t_optmgmtT_DIS struct t_disconT_UNITDATA struct t_unitdataT_UDERROR struct t_uderrT_INFO struct t_info</code></pre><p>where each of these structures may subsequently beused as an argument to one or more transport functions.<p>Each of the above structures, except T_INFO,contains at least one field of type<B>struct</B><B>netbuf</B>.For each field of this type, the user may specify thatthe buffer for that field should be allocated as well.The length of the buffer allocated will be equal to or greater thanthe appropriate size as returned in the<I>info</I>argument of<i><a href="t_open.html">t_open()</a></i>or<i><a href="t_getinfo.html">t_getinfo()</a></i>.The relevant fields of the<I>info</I>argument are described in the following list.The<I>fields</I>argument specifies which buffers to allocate, where the argument is thebitwise-or of any of the following:<dl compact><dt>T_ADDR<dd>The<I>addr</I>field of the<B>t_bind</B>,<B>t_call</B>,<B>t_unitdata</B>or<B>t_uderr</B>structures.<dt>T_OPT<dd>The<I>opt</I>field of the<B>t_optmgmt</B>,<B>t_call</B>,<B>t_unitdata</B>or<B>t_uderr</B>structures.<dt>T_UDATA<dd>The<I>udata</I>field of the<B>t_call</B>,<B>t_discon</B>or<B>t_unitdata</B>structures.<dt>T_ALL<dd>All relevant fields of the given structure. Fields which are not supportedby the transport provider specified by<I>fd</I>will not be allocated.</dl><p>For each relevant field specified in<I>fields</I>,<i>t_alloc()</i>will allocate memory for the buffer associated with the field,and initialise the<I>len</I>field to zero and the<I>buf</I>pointerand<I>maxlen</I>field accordingly.Irrelevant or unknown values passed in fields are ignored.Sincethe length of the buffer allocated will be based on the same sizeinformation that is returned to the user on a call to<i><a href="t_open.html">t_open()</a></i>and<i><a href="t_getinfo.html">t_getinfo()</a></i>,<I>fd</I>must refer to the transport endpoint through which the newlyallocated structure will be passed.In the case where a T_INFO structure is to be allocated,<I>fd</I>may be set to any value.In this way the appropriatesize information can be accessed.If the size value associated with any specified field is T_INVALID (see <i><a href="t_open.html">t_open()</a></i>or <i><a href="t_getinfo.html">t_getinfo()</a></i>),<i>t_alloc()</i>will be unable to determine the size of the buffer to allocate and will fail, setting <I>t_errno</I>to [TSYSERR] and <I>errno</I>to [EINVAL]. If the size value associated withany specified field is T_INFINITE (see <i><a href="t_open.html">t_open()</a></i>or<i><a href="t_getinfo.html">t_getinfo()</a></i>),then the behaviour of <i>t_alloc()</i>is implementation-defined.For any field not specified in<I>fields</I>,<I>buf</I>will be set to the null pointerand<I>len</I>and<I>maxlen</I>will be set to zero.<p>The pointer returned if the allocation succeeds issuitably aligned so that it can be assigned to a pointerto any type of object and then used to access such anobject or array of such objects in the space allocated.<p>Use of<i>t_alloc()</i>to allocate structures will help ensure the compatibility of userprograms with future releases of the transport interface functions.</blockquote><h4>VALID STATES</h4><blockquote>ALL - apart from T_UNINIT</blockquote><h4>ERRORS</h4><blockquote>On failure,<I>t_errno</I>is set to one of the following:<dl compact><dt>[TBADF]<dd><B>struct_type</B>is other than T_INFO andthe specified file descriptor does not refer to a transport endpoint.<dt>[TNOSTRUCTYPE]<dd>Unsupported<I>struct_type</I>requested.This can include a request for a structure type which is inconsistent withthe transport provider typespecified, that is, connection-mode or connectionless-mode.<dt>[TPROTO]<dd>This error indicates that a communication problem has been detected betweenXTI and the transport provider for which there is no other suitable XTIerror<I>(t_errno)</I>.<dt>[TSYSERR]<dd>A system error has occurred during execution of this function.</dl></blockquote><h4>RETURN VALUE</h4><blockquote>On successful completion,<i>t_alloc()</i>returns a pointer to the newly allocated structure.On failure, a null pointer is returned.</blockquote><h4>SEE ALSO</h4><blockquote><i><a href="t_free.html">t_free()</a></i>,<i><a href="t_getinfo.html">t_getinfo()</a></i>,<i><a href="t_open.html">t_open()</a></i>.</blockquote><hr size=2 noshade><center><font size=2>UNIX ® is a registered Trademark of The Open Group.<br>Copyright © 1997 The Open Group<br> [ <a href="../index.html">Main Index</a> | <a href="../xshix.html">XSH</a> | <a href="../xcuix.html">XCU</a> | <a href="../xbdix.html">XBD</a> | <a href="../cursesix.html">XCURSES</a> | <a href="../xnsix.html">XNS</a> ]</font></center><hr size=2 noshade></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -