Provided by: libnbd-dev_1.2.2-1ubuntu2_amd64 bug


       nbd_create, nbd_close, nbd_get_error, nbd_get_errno - create libnbd handles and fetch


        #include <libnbd.h>

        struct nbd_handle *nbd;

        struct nbd_handle *nbd_create (void);
        void nbd_close (struct nbd_handle *nbd);
        const char *nbd_get_error (void);
        int nbd_get_errno (void);


        #include <libnbd.h>

        main ()
          struct nbd_handle *nbd;

          nbd = nbd_create ();
          if (nbd == NULL) {
            fprintf (stderr, "%s\n", nbd_get_error ());
            nbd_close (nbd);
            exit (EXIT_FAILURE);
          nbd_close (nbd);
          exit (EXIT_SUCCESS);

        cc prog.c -o prog -lnbd
        cc prog.c -o prog `pkg-config libnbd --cflags --libs`


   Create and close handles
       struct nbd_handle is an opaque structure which describes an NBD client handle and the
       connection to an NBD server.

       nbd_create creates a new handle.  It returns a pointer to the opaque handle structure.

       On error this returns "NULL".  See "ERROR HANDLING" in libnbd(3) for how to get further
       details of the error.

       nbd_close closes the handle and frees any associated resources.  The final status of any
       command that has not been retired (whether by nbd_aio_command_completed(3) or by a low-
       level completion callback returning 1) is lost.  This function is not safe to call while
       any other thread is still using any "nbd_*" API on the same handle.  This function can
       block in the case where we wait for a subprocess (eg. one created with

   Getting the latest error message in the thread
       See "ERROR HANDLING" in libnbd(3) for more discussion of how error handling works in

       nbd_get_error returns the most recent error message in the current thread.  The error
       message is only valid if called immediately after the failing call, from the same thread.
       The error string returned will be freed up next time any libnbd API is called from the
       same thread, so if you need to keep it you must make a copy.

       This should never return "NULL" provided there was an error returned from the immediately
       preceding libnbd call in the current thread.

       nbd_get_errno returns the most recent "errno" in the current thread.  Not all errors have
       corresponding errnos, so even if there has been an error this may return 0.  Error codes
       are the standard ones from "<errno.h>".




       Eric Blake

       Richard W.M. Jones


       Copyright (C) 2019 Red Hat Inc.


       This library is free software; you can redistribute it and/or modify it under the terms of
       the GNU Lesser General Public License as published by the Free Software Foundation; either
       version 2 of the License, or (at your option) any later version.

       This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
       without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
       See the GNU Lesser General Public License for more details.

       You should have received a copy of the GNU Lesser General Public License along with this
       library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
       Floor, Boston, MA 02110-1301 USA