---
name: "util.c"
section: "3"
platform: "linux"
package: "libmtp"
version: "1.1.23-1"
release: "Arch Linux 2026-11-01"
platforms: ["linux"]
url: "https://new.carta.tech/util.c"
---

# util.c(3)

## NAME

util.c

## SYNOPSIS

\#include \<sys/time.h\>\
 \#include \<unistd.h\>\
 \#include \<stdio.h\>\
 \#include \<stdlib.h\>\
 \#include \<errno.h\>\
 \#include \<sys/stat.h\>\
 \#include \<fcntl.h\>\
 \#include \<string.h\>\
 \#include 'config.h'\
 \#include 'libmtp.h'\
 \#include 'util.h'\

### Functions

void **device\_unknown** (const int dev\_number, const int id\_vendor, const int id\_product)\
 void **data\_dump** (FILE \*f, void \*buf, uint32\_t n)\
 void **data\_dump\_ascii** (FILE \*f, void \*buf, uint32\_t n, uint32\_t dump\_boundry)\
 char \* **strndup** (const char \*s, size\_t n)\

## Detailed Description

This file contains generic utility functions such as can be used for debugging for example.

Copyright (C) 2005-2007 Linus Walleij triad@df.lth.se

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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

## Function Documentation

### void data\_dump (FILE \* f, void \* buf, uint32\_t n)

This dumps out a number of bytes to a textual, hexadecimal dump.

**Parameters**

*f* the file to dump to (e.g. stdout or stderr) \
 *buf* a pointer to the buffer containing the bytes to be dumped out in hex \
 *n* the number of bytes to dump from this buffer

### void data\_dump\_ascii (FILE \* f, void \* buf, uint32\_t n, uint32\_t dump\_boundry)

This dumps out a number of bytes to a textual, hexadecimal dump, and also prints out the string ASCII representation for each line of bytes. It will also print the memory address offset from a certain boundry.

**Parameters**

*f* the file to dump to (e.g. stdout or stderr) \
 *buf* a pointer to the buffer containing the bytes to be dumped out in hex \
 *n* the number of bytes to dump from this buffer \
 *dump\_boundry* the address offset to start at (usually 0)

### void device\_unknown (const int dev\_number, const int id\_vendor, const int id\_product)

This prints to stdout info about device being UNKNOWN, its ids, and libmtp's version number.

**Parameters**

*dev\_number* the device number \
 *id\_vendor* vendor ID from the usb\_device\_desc struct \
 *id\_product* product ID from the usb\_device\_desc struct

Referenced by **LIBMTP\_Detect\_Raw\_Devices()**, and **LIBMTP\_Detect\_Raw\_Devices()**.

## Author

Generated automatically by Doxygen for libmtp from the source code.
