libusbg: Replace array lengths with defines

Replace hard coded value of 256 by two constant
defines, USBG_MAX_STR_LENGTH and USBG_MAX_PATH_LENGTH
Define USBG_MAX_NAME_LENGTH for name[] array

Signed-off-by: Stanislaw Wadas <s.wadas@samsung.com>
libusbg: Add fputs()/fgets()/fprintf() error

handling

Add error handling to fputs()/fgets()/fprintf() functions.

Signed-off-by: Stanislaw Wadas <s.wadas@samsung.com>
libusbg: Move mkdir functions

Call mkdir() function after successful memory allocation
and gadget function creation.

Signed-off-by: Stanislaw Wadas <s.wadas@samsung.com>
libusbg: Add inline to gadget_write_string().

Add inline to gadget_write_string().

Signed-off-by: Stanislaw Wadas <s.wadas@samsung.com>
libusbg: Surround header with include guards.

Surround header with include guards to protect against
multiple inclusion.

Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
libusbg: Add missing return statement in non-void functions.

Add return 0 in functions which return non-void to
suppress compiler complaint.

Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
libusbg: Fix gadget-acm-ecm example to cleanup at exit.

Make use of previously unused variable ret to cleanup
after successful gadget creation.

Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
libusbg: Move directory creation before writing attributes.

Change order of gadget creation and attribute writting
to fix  No such file or directory error while creating
new gadget.

Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
libusbg: Fix memory leak when unable to create directory.

Free the memory allocated for gadget/config/function structure
when faild to create suitable directory.

Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
libusbg: Add error handling to gadget_read_string().

Add error handling when gadget_read_buf() returns NULL.
If read of string fails, the string should be set as empty.

Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
libusbg: Add missing config attrs parsing while new config creation.

Afther creation of configuration its attributes left uninitialized.
Config attrs should be initialized with default values provided
by kernel.

Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
libusbg: Separate parsing gadget attributes and strings.

Gadget attributes and strings are logically independent,
so they should be initialized in separate functions.

Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
libusbg: Initialize gadget attributes and strings while gadget creation.

Fix gadget_create_gadget function to initialize gadget attributes
and strings with default values provided by kernel.

Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
libusbg: Move symlink creation after memory allocation.

Move creation of symlink after memory allocation for
binding structure. Fix missing initialization of parent.

Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
libusbg: Replace memcpy with structure assignment.

Use the assign operator for structure instead of using
memcpy with hard coded size.

Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
libusbg: Replace directory names with defines.

Replace strings, functions, configs strings placed
everywhere in code with macro defintions STRINGS_DIR,
FUNCTIONS_DIR and CONFIGS_DIR.

Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
libusbg: Separate gadget attributes from gadget.

Gadget attributes should be placed in external structure
because they are almost that same as USB device descriptor.

Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
libusbg: Change gadget attributes size and names.

Rename all gadget attributes to be consistent with usb
standard and libusb. Change also field size and order
to allow direct memcpy from libusb_device_descriptor.

Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
libusbg: Separate gadget strings from gadget.

Gadget strings are not logically part of gadget, so should
be separated.

Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
libusbg: Use dedicated macro instead of copy-paste code.

Insterting in string order has been done few times.
It was almost the same piece of code copied and pasted with
some minor changes. All those pieces has been replaced with
new macro INSERT_TAILQ_STRING_ORDER which does all the job.

Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>