INSQUE(3)                  POSIX Programmer's Manual                 INSQUE(3)



PPRROOLLOOGG
       This manual page is part of the POSIX Programmer's Manual.  The OS
       implementation of this interface may differ (consult the corresponding
       OS manual page for details of OS behavior), or the interface may not be
       implemented on OS.


NNAAMMEE
       insque, remque -- insert or remove an element in a queue

SSYYNNOOPPSSIISS
       #include <search.h>

       void insque(void *_e_l_e_m_e_n_t, void *_p_r_e_d);
       void remque(void *_e_l_e_m_e_n_t);

DDEESSCCRRIIPPTTIIOONN
       The _i_n_s_q_u_e() and _r_e_m_q_u_e() functions shall manipulate queues built from
       doubly-linked lists.  The queue can be either circular or linear. An
       application using _i_n_s_q_u_e() or _r_e_m_q_u_e() shall ensure it defines a
       structure in which the first two members of the structure are pointers
       to the same type of structure, and any further members are application-
       specific. The first member of the structure is a forward pointer to the
       next entry in the queue. The second member is a backward pointer to the
       previous entry in the queue.  If the queue is linear, the queue is
       terminated with null pointers. The names of the structure and of the
       pointer members are not subject to any special restriction.

       The _i_n_s_q_u_e() function shall insert the element pointed to by _e_l_e_m_e_n_t
       into a queue immediately after the element pointed to by _p_r_e_d.

       The _r_e_m_q_u_e() function shall remove the element pointed to by _e_l_e_m_e_n_t
       from a queue.

       If the queue is to be used as a linear list, invoking _i_n_s_q_u_e(&_e_l_e_m_e_n_t,
       NULL), where _e_l_e_m_e_n_t is the initial element of the queue, shall
       initialize the forward and backward pointers of _e_l_e_m_e_n_t to null
       pointers.

       If the queue is to be used as a circular list, the application shall
       ensure it initializes the forward pointer and the backward pointer of
       the initial element of the queue to the element's own address.

RREETTUURRNN VVAALLUUEE
       The _i_n_s_q_u_e() and _r_e_m_q_u_e() functions do not return a value.

EERRRROORRSS
       No errors are defined.

       _T_h_e _f_o_l_l_o_w_i_n_g _s_e_c_t_i_o_n_s _a_r_e _i_n_f_o_r_m_a_t_i_v_e_.

EEXXAAMMPPLLEESS
   CCrreeaattiinngg aa LLiinneeaarr LLiinnkkeedd LLiisstt
       The following example creates a linear linked list.

           ##iinncclluuddee <<sseeaarrcchh..hh>>
           ......
           ssttrruucctt mmyyqquuee eelleemmeenntt11;;
           ssttrruucctt mmyyqquuee eelleemmeenntt22;;

           char *data1 = "DATA1";
           char *data2 = "DATA2";
           ...
           element1.data = data1;
           element2.data = data2;

           insque (&element1, NULL);
           insque (&element2, &element1);

   CCrreeaattiinngg aa CCiirrccuullaarr LLiinnkkeedd LLiisstt
       The following example creates a circular linked list.

           ##iinncclluuddee <<sseeaarrcchh..hh>>
           ......
           ssttrruucctt mmyyqquuee eelleemmeenntt11;;
           ssttrruucctt mmyyqquuee eelleemmeenntt22;;

           char *data1 = "DATA1";
           char *data2 = "DATA2";
           ...
           element1.data = data1;
           element2.data = data2;

           element1.fwd = &element1;
           element1.bck = &element1;

           insque (&element2, &element1);

   RReemmoovviinngg aann EElleemmeenntt
       The following example removes the element pointed to by _e_l_e_m_e_n_t_1.

           ##iinncclluuddee <<sseeaarrcchh..hh>>
           ......
           ssttrruucctt mmyyqquuee eelleemmeenntt11;;
           ......
           rreemmqquuee ((&&eelleemmeenntt11));;

AAPPPPLLIICCAATTIIOONN UUSSAAGGEE
       The historical implementations of these functions described the
       arguments as being of type ssttrruucctt qqeelleemm ** rather than as being of type
       vvooiidd ** as defined here. In those implementations, ssttrruucctt qqeelleemm was
       commonly defined in _<_s_e_a_r_c_h_._h_> as:

           ssttrruucctt qqeelleemm {{
               ssttrruucctt qqeelleemm  **qq__ffoorrww;;
               ssttrruucctt qqeelleemm  **qq__bbaacckk;;
           }};;

       Applications using these functions, however, were never able to use
       this structure directly since it provided no room for the actual data
       contained in the elements. Most applications defined structures that
       contained the two pointers as the initial elements and also provided
       space for, or pointers to, the object's data. Applications that used
       these functions to update more than one type of table also had the
       problem of specifying two or more different structures with the same
       name, if they literally used ssttrruucctt qqeelleemm as specified.

       As described here, the implementations were actually expecting a
       structure type where the first two members were forward and backward
       pointers to structures. With C compilers that didn't provide function
       prototypes, applications used structures as specified in the
       DESCRIPTION above and the compiler did what the application expected.

       If this method had been carried forward with an ISO C standard compiler
       and the historical function prototype, most applications would have to
       be modified to cast pointers to the structures actually used to be
       pointers to ssttrruucctt qqeelleemm to avoid compilation warnings. By specifying
       vvooiidd ** as the argument type, applications do not need to change (unless
       they specifically referenced ssttrruucctt qqeelleemm and depended on it being
       defined in _<_s_e_a_r_c_h_._h_>).

RRAATTIIOONNAALLEE
       None.

FFUUTTUURREE DDIIRREECCTTIIOONNSS
       None.

SSEEEE AALLSSOO
       The Base Definitions volume of POSIX.1-2008, <<sseeaarrcchh..hh>>

CCOOPPYYRRIIGGHHTT
       Portions of this text are reprinted and reproduced in electronic form
       from IEEE Std 1003.1, 2013 Edition, Standard for Information Technology
       -- Portable Operating System Interface (POSIX), The Open Group Base
       Specifications Issue 7, Copyright (C) 2013 by the Institute of
       Electrical and Electronics Engineers, Inc and The Open Group.  (This is
       POSIX.1-2008 with the 2013 Technical Corrigendum 1 applied.) In the
       event of any discrepancy between this version and the original IEEE and
       The Open Group Standard, the original IEEE and The Open Group Standard
       is the referee document. The original Standard can be obtained online
       at http://www.unix.org/online.html .

       Any typographical or formatting errors that appear in this page are
       most likely to have been introduced during the conversion of the source
       files to man page format. To report such errors, see
       https://www.kernel.org/doc/man-pages/reporting_bugs.html .



IEEE/The Open Group                  2013                            INSQUE(3)
