<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/> <meta http-equiv="X-UA-Compatible" content="IE=9"/> <meta name="generator" content="Doxygen 1.8.13"/> <meta name="viewport" content="width=device-width, initial-scale=1"/> <title>libmtp: detect.c</title> <link href="tabs.css" rel="stylesheet" type="text/css"/> <script type="text/javascript" src="jquery.js"></script> <script type="text/javascript" src="dynsections.js"></script> <link href="doxygen.css" rel="stylesheet" type="text/css" /> </head> <body> <div id="top"><!-- do not remove this div, it is closed by doxygen! --> <div id="titlearea"> <table cellspacing="0" cellpadding="0"> <tbody> <tr style="height: 56px;"> <td id="projectalign" style="padding-left: 0.5em;"> <div id="projectname">libmtp  <span id="projectnumber">1.1.16</span> </div> </td> </tr> </tbody> </table> </div> <!-- end header part --> <!-- Generated by Doxygen 1.8.13 --> <script type="text/javascript" src="menudata.js"></script> <script type="text/javascript" src="menu.js"></script> <script type="text/javascript"> $(function() { initMenu('',false,false,'search.php','Search'); }); </script> <div id="main-nav"></div> </div><!-- top --> <div class="header"> <div class="headertitle"> <div class="title">detect.c</div> </div> </div><!--header--> <div class="contents"> <div class="fragment"><div class="line"></div><div class="line"><span class="preprocessor">#include "common.h"</span></div><div class="line"><span class="preprocessor">#include "util.h"</span></div><div class="line"><span class="preprocessor">#include <unistd.h></span></div><div class="line"><span class="preprocessor">#include <stdlib.h></span></div><div class="line"><span class="preprocessor">#include <stdio.h></span></div><div class="line"><span class="preprocessor">#include <string.h></span></div><div class="line"><span class="preprocessor">#include <errno.h></span></div><div class="line"></div><div class="line"><span class="preprocessor">#define XML_BUFSIZE 0x10000</span></div><div class="line"></div><div class="line"><span class="keyword">static</span> <span class="keywordtype">void</span> dump_xml_fragment(uint8_t *buf, uint32_t len)</div><div class="line">{</div><div class="line"> <span class="keyword">static</span> <span class="keywordtype">int</span> endianness = 0; <span class="comment">// 0 = LE, 1 = BE</span></div><div class="line"> uint32_t bp = 0;</div><div class="line"></div><div class="line"> <span class="keywordflow">while</span> (bp < len) {</div><div class="line"> <span class="keywordflow">if</span> (buf[bp+0] == 0xFF && buf[bp+1] == 0xFE) {</div><div class="line"> endianness = 0;</div><div class="line"> } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (buf[bp+0] == 0xFE && buf[bp+1] == 0xff) {</div><div class="line"> endianness = 1;</div><div class="line"> } <span class="keywordflow">else</span> {</div><div class="line"> uint16_t tmp;</div><div class="line"></div><div class="line"> <span class="keywordflow">if</span> (endianness == 0) {</div><div class="line"> tmp = buf[bp+1] << 8 | buf[bp+0];</div><div class="line"> } <span class="keywordflow">else</span> {</div><div class="line"> tmp = buf[bp+0] << 8 | buf[bp+1];</div><div class="line"> }</div><div class="line"> <span class="comment">// Fix this some day, we only print ISO 8859-1 correctly here,</span></div><div class="line"> <span class="comment">// should atleast support UTF-8.</span></div><div class="line"> printf(<span class="stringliteral">"%c"</span>, (uint8_t) tmp);</div><div class="line"> }</div><div class="line"> bp += 2;</div><div class="line"> }</div><div class="line"> printf(<span class="stringliteral">"\n"</span>);</div><div class="line">}</div><div class="line"></div><div class="line"><span class="keywordtype">int</span> main (<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span> **argv)</div><div class="line">{</div><div class="line"> <a name="_a0"></a><a class="code" href="structLIBMTP__raw__device__struct.html">LIBMTP_raw_device_t</a> * rawdevices;</div><div class="line"> <span class="keywordtype">int</span> numrawdevices;</div><div class="line"> <a class="code" href="group__types.html#ga1e5fcb2945c5e60bf5bd9e847a904fa8">LIBMTP_error_number_t</a> err;</div><div class="line"> <span class="keywordtype">int</span> i;</div><div class="line"></div><div class="line"> <span class="keywordtype">int</span> opt;</div><div class="line"> <span class="keyword">extern</span> <span class="keywordtype">int</span> optind;</div><div class="line"> <span class="keyword">extern</span> <span class="keywordtype">char</span> *optarg;</div><div class="line"></div><div class="line"> <span class="keywordflow">while</span> ((opt = getopt(argc, argv, <span class="stringliteral">"d"</span>)) != -1 ) {</div><div class="line"> <span class="keywordflow">switch</span> (opt) {</div><div class="line"> <span class="keywordflow">case</span> <span class="charliteral">'d'</span>:</div><div class="line"> <a name="a1"></a><a class="code" href="group__internals.html#gab855a6f761b0210b1d986d5a02a22c10">LIBMTP_Set_Debug</a>(LIBMTP_DEBUG_PTP | LIBMTP_DEBUG_DATA);</div><div class="line"> <span class="keywordflow">break</span>;</div><div class="line"> }</div><div class="line"> }</div><div class="line"></div><div class="line"> argc -= optind;</div><div class="line"> argv += optind;</div><div class="line"></div><div class="line"> <a name="a2"></a><a class="code" href="group__internals.html#gaaca880ea9ab434e8cf1a1051128318ef">LIBMTP_Init</a>();</div><div class="line"></div><div class="line"> fprintf(stdout, <span class="stringliteral">"libmtp version: "</span> LIBMTP_VERSION_STRING <span class="stringliteral">"\n\n"</span>);</div><div class="line"></div><div class="line"> fprintf(stdout, <span class="stringliteral">"Listing raw device(s)\n"</span>);</div><div class="line"> err = <a name="a3"></a><a class="code" href="group__basic.html#gae54131d2a1ed21292fa270921afb9d46">LIBMTP_Detect_Raw_Devices</a>(&rawdevices, &numrawdevices);</div><div class="line"> <span class="keywordflow">switch</span>(err) {</div><div class="line"> <span class="keywordflow">case</span> LIBMTP_ERROR_NO_DEVICE_ATTACHED:</div><div class="line"> fprintf(stdout, <span class="stringliteral">" No raw devices found.\n"</span>);</div><div class="line"> <span class="keywordflow">return</span> 0;</div><div class="line"> <span class="keywordflow">case</span> LIBMTP_ERROR_CONNECTING:</div><div class="line"> fprintf(stderr, <span class="stringliteral">"Detect: There has been an error connecting. Exiting\n"</span>);</div><div class="line"> <span class="keywordflow">return</span> 1;</div><div class="line"> <span class="keywordflow">case</span> LIBMTP_ERROR_MEMORY_ALLOCATION:</div><div class="line"> fprintf(stderr, <span class="stringliteral">"Detect: Encountered a Memory Allocation Error. Exiting\n"</span>);</div><div class="line"> <span class="keywordflow">return</span> 1;</div><div class="line"> <span class="keywordflow">case</span> LIBMTP_ERROR_NONE:</div><div class="line"> {</div><div class="line"> <span class="keywordtype">int</span> i;</div><div class="line"></div><div class="line"> fprintf(stdout, <span class="stringliteral">" Found %d device(s):\n"</span>, numrawdevices);</div><div class="line"> <span class="keywordflow">for</span> (i = 0; i < numrawdevices; i++) {</div><div class="line"> <span class="keywordflow">if</span> (rawdevices[i].device_entry.vendor != NULL ||</div><div class="line"> rawdevices[i].<a name="a4"></a><a class="code" href="structLIBMTP__raw__device__struct.html#af01da354d13112259a3f210fecec6283">device_entry</a>.<a name="a5"></a><a class="code" href="structLIBMTP__device__entry__struct.html#ad392e158dfb9bb0aef58d180b98357e5">product</a> != NULL) {</div><div class="line"> fprintf(stdout, <span class="stringliteral">" %s: %s (%04x:%04x) @ bus %d, dev %d\n"</span>,</div><div class="line"> rawdevices[i].device_entry.vendor,</div><div class="line"> rawdevices[i].<a class="code" href="structLIBMTP__raw__device__struct.html#af01da354d13112259a3f210fecec6283">device_entry</a>.<a class="code" href="structLIBMTP__device__entry__struct.html#ad392e158dfb9bb0aef58d180b98357e5">product</a>,</div><div class="line"> rawdevices[i].<a class="code" href="structLIBMTP__raw__device__struct.html#af01da354d13112259a3f210fecec6283">device_entry</a>.<a name="a6"></a><a class="code" href="structLIBMTP__device__entry__struct.html#a132af448075c74acbbc389d074ce1f97">vendor_id</a>,</div><div class="line"> rawdevices[i].<a class="code" href="structLIBMTP__raw__device__struct.html#af01da354d13112259a3f210fecec6283">device_entry</a>.<a name="a7"></a><a class="code" href="structLIBMTP__device__entry__struct.html#a450dfc3a7c9d46f998ad1599df776193">product_id</a>,</div><div class="line"> rawdevices[i].<a name="a8"></a><a class="code" href="structLIBMTP__raw__device__struct.html#af2dae736de12f8ad189b8ea7d0688ab8">bus_location</a>,</div><div class="line"> rawdevices[i].<a name="a9"></a><a class="code" href="structLIBMTP__raw__device__struct.html#ada1008955e7c65a933f29105a8f28104">devnum</a>);</div><div class="line"> } <span class="keywordflow">else</span> {</div><div class="line"> fprintf(stdout, <span class="stringliteral">" %04x:%04x @ bus %d, dev %d\n"</span>,</div><div class="line"> rawdevices[i].device_entry.vendor_id,</div><div class="line"> rawdevices[i].<a class="code" href="structLIBMTP__raw__device__struct.html#af01da354d13112259a3f210fecec6283">device_entry</a>.<a class="code" href="structLIBMTP__device__entry__struct.html#a450dfc3a7c9d46f998ad1599df776193">product_id</a>,</div><div class="line"> rawdevices[i].<a class="code" href="structLIBMTP__raw__device__struct.html#af2dae736de12f8ad189b8ea7d0688ab8">bus_location</a>,</div><div class="line"> rawdevices[i].<a class="code" href="structLIBMTP__raw__device__struct.html#ada1008955e7c65a933f29105a8f28104">devnum</a>);</div><div class="line"> }</div><div class="line"> }</div><div class="line"> }</div><div class="line"> <span class="keywordflow">break</span>;</div><div class="line"> <span class="keywordflow">case</span> LIBMTP_ERROR_GENERAL:</div><div class="line"> <span class="keywordflow">default</span>:</div><div class="line"> fprintf(stderr, <span class="stringliteral">"Unknown connection error.\n"</span>);</div><div class="line"> <span class="keywordflow">return</span> 1;</div><div class="line"> }</div><div class="line"></div><div class="line"> <span class="comment">/* Iterate over connected MTP devices */</span></div><div class="line"> fprintf(stdout, <span class="stringliteral">"Attempting to connect device(s)\n"</span>);</div><div class="line"> <span class="keywordflow">for</span> (i = 0; i < numrawdevices; i++) {</div><div class="line"> <a name="_a10"></a><a class="code" href="structLIBMTP__mtpdevice__struct.html">LIBMTP_mtpdevice_t</a> *device;</div><div class="line"> <a name="_a11"></a><a class="code" href="structLIBMTP__devicestorage__struct.html">LIBMTP_devicestorage_t</a> *storage;</div><div class="line"> <span class="keywordtype">char</span> *friendlyname;</div><div class="line"> <span class="keywordtype">char</span> *syncpartner;</div><div class="line"> <span class="keywordtype">char</span> *sectime;</div><div class="line"> <span class="keywordtype">char</span> *devcert;</div><div class="line"> uint16_t *filetypes;</div><div class="line"> uint16_t filetypes_len;</div><div class="line"> uint8_t maxbattlevel;</div><div class="line"> uint8_t currbattlevel;</div><div class="line"> <span class="keywordtype">int</span> ret;</div><div class="line"></div><div class="line"> device = <a name="a12"></a><a class="code" href="group__basic.html#ga8834a0dd3349ec620fff87a209396d01">LIBMTP_Open_Raw_Device_Uncached</a>(&rawdevices[i]);</div><div class="line"> <span class="keywordflow">if</span> (device == NULL) {</div><div class="line"> fprintf(stderr, <span class="stringliteral">"Unable to open raw device %d\n"</span>, i);</div><div class="line"> <span class="keywordflow">continue</span>;</div><div class="line"> }</div><div class="line"></div><div class="line"> <a name="a13"></a><a class="code" href="group__basic.html#ga682c81a83fa04b2caf5c962db1eaff82">LIBMTP_Dump_Errorstack</a>(device);</div><div class="line"> <a name="a14"></a><a class="code" href="group__basic.html#ga6c05b927310ac830c149ae3eeae94047">LIBMTP_Clear_Errorstack</a>(device);</div><div class="line"> <a name="a15"></a><a class="code" href="group__basic.html#gaeabdf4e3d2f387ee357755ae356cc105">LIBMTP_Dump_Device_Info</a>(device);</div><div class="line"></div><div class="line"> printf(<span class="stringliteral">"MTP-specific device properties:\n"</span>);</div><div class="line"> <span class="comment">// The friendly name</span></div><div class="line"> friendlyname = <a name="a16"></a><a class="code" href="group__basic.html#ga3d9d80c2239c923ee20eca28060b8188">LIBMTP_Get_Friendlyname</a>(device);</div><div class="line"> <span class="keywordflow">if</span> (friendlyname == NULL) {</div><div class="line"> fprintf(stdout, <span class="stringliteral">" Friendly name: (NULL)\n"</span>);</div><div class="line"> } <span class="keywordflow">else</span> {</div><div class="line"> fprintf(stdout, <span class="stringliteral">" Friendly name: %s\n"</span>, friendlyname);</div><div class="line"> free(friendlyname);</div><div class="line"> }</div><div class="line"> syncpartner = <a name="a17"></a><a class="code" href="group__basic.html#ga243929e37e36da1a60ec159ebdec6d29">LIBMTP_Get_Syncpartner</a>(device);</div><div class="line"> <span class="keywordflow">if</span> (syncpartner == NULL) {</div><div class="line"> fprintf(stdout, <span class="stringliteral">" Synchronization partner: (NULL)\n"</span>);</div><div class="line"> } <span class="keywordflow">else</span> {</div><div class="line"> fprintf(stdout, <span class="stringliteral">" Synchronization partner: %s\n"</span>, syncpartner);</div><div class="line"> free(syncpartner);</div><div class="line"> }</div><div class="line"></div><div class="line"> <span class="comment">// Some battery info</span></div><div class="line"> ret = <a name="a18"></a><a class="code" href="group__basic.html#gae76db5d99c3275da90c01c1eb735c68c">LIBMTP_Get_Batterylevel</a>(device, &maxbattlevel, &currbattlevel);</div><div class="line"> <span class="keywordflow">if</span> (ret == 0) {</div><div class="line"> fprintf(stdout, <span class="stringliteral">" Battery level %d of %d (%d%%)\n"</span>,currbattlevel, maxbattlevel,</div><div class="line"> (<span class="keywordtype">int</span>) ((<span class="keywordtype">float</span>) currbattlevel/ (<span class="keywordtype">float</span>) maxbattlevel * 100.0));</div><div class="line"> } <span class="keywordflow">else</span> {</div><div class="line"> <span class="comment">// Silently ignore. Some devices does not support getting the</span></div><div class="line"> <span class="comment">// battery level.</span></div><div class="line"> <a class="code" href="group__basic.html#ga6c05b927310ac830c149ae3eeae94047">LIBMTP_Clear_Errorstack</a>(device);</div><div class="line"> }</div><div class="line"></div><div class="line"> ret = <a name="a19"></a><a class="code" href="group__basic.html#ga7b6ada53eea9960c48be42289249e2d6">LIBMTP_Get_Supported_Filetypes</a>(device, &filetypes, &filetypes_len);</div><div class="line"> <span class="keywordflow">if</span> (ret == 0) {</div><div class="line"> uint16_t i;</div><div class="line"></div><div class="line"> printf(<span class="stringliteral">"libmtp supported (playable) filetypes:\n"</span>);</div><div class="line"> <span class="keywordflow">for</span> (i = 0; i < filetypes_len; i++) {</div><div class="line"> fprintf(stdout, <span class="stringliteral">" %s\n"</span>, <a name="a20"></a><a class="code" href="group__files.html#ga9d920e6a6a80d9497076798c0f54ce34">LIBMTP_Get_Filetype_Description</a>(filetypes[i]));</div><div class="line"> }</div><div class="line"> } <span class="keywordflow">else</span> {</div><div class="line"> <a class="code" href="group__basic.html#ga682c81a83fa04b2caf5c962db1eaff82">LIBMTP_Dump_Errorstack</a>(device);</div><div class="line"> <a class="code" href="group__basic.html#ga6c05b927310ac830c149ae3eeae94047">LIBMTP_Clear_Errorstack</a>(device);</div><div class="line"> }</div><div class="line"></div><div class="line"> <span class="comment">// Secure time XML fragment</span></div><div class="line"> ret = <a name="a21"></a><a class="code" href="group__basic.html#ga18ec60e1645241cb8639e0b9e21eb8a0">LIBMTP_Get_Secure_Time</a>(device, &sectime);</div><div class="line"> <span class="keywordflow">if</span> (ret == 0 && sectime != NULL) {</div><div class="line"> fprintf(stdout, <span class="stringliteral">"\nSecure Time:\n%s\n"</span>, sectime);</div><div class="line"> free(sectime);</div><div class="line"> } <span class="keywordflow">else</span> {</div><div class="line"> <span class="comment">// Silently ignore - there may be devices not supporting secure time.</span></div><div class="line"> <a class="code" href="group__basic.html#ga6c05b927310ac830c149ae3eeae94047">LIBMTP_Clear_Errorstack</a>(device);</div><div class="line"> }</div><div class="line"></div><div class="line"> <span class="comment">// Device certificate XML fragment</span></div><div class="line"> <span class="keywordflow">if</span> (rawdevices[i].device_entry.vendor_id == 0x041e) {</div><div class="line"> <span class="comment">/*</span></div><div class="line"><span class="comment"> * This code is currently disabled except for vendors we</span></div><div class="line"><span class="comment"> * know does support it: all devices say that</span></div><div class="line"><span class="comment"> * they support getting a device certificate but a lot of</span></div><div class="line"><span class="comment"> * them obviously doesn't, instead they crash when you try</span></div><div class="line"><span class="comment"> * to obtain it.</span></div><div class="line"><span class="comment"> */</span></div><div class="line"> ret = <a name="a22"></a><a class="code" href="group__basic.html#ga73185af9ad56df247732fdcc7a6bf62c">LIBMTP_Get_Device_Certificate</a>(device, &devcert);</div><div class="line"> <span class="keywordflow">if</span> (ret == 0 && devcert != NULL) {</div><div class="line"> fprintf(stdout, <span class="stringliteral">"\nDevice Certificate:\n%s\n"</span>, devcert);</div><div class="line"> free(devcert);</div><div class="line"> } <span class="keywordflow">else</span> {</div><div class="line"> fprintf(stdout, <span class="stringliteral">"Unable to acquire device certificate, perhaps this device "</span></div><div class="line"> <span class="stringliteral">"does not support this\n"</span>);</div><div class="line"> <a class="code" href="group__basic.html#ga682c81a83fa04b2caf5c962db1eaff82">LIBMTP_Dump_Errorstack</a>(device);</div><div class="line"> <a class="code" href="group__basic.html#ga6c05b927310ac830c149ae3eeae94047">LIBMTP_Clear_Errorstack</a>(device);</div><div class="line"> }</div><div class="line"> }</div><div class="line"></div><div class="line"> <span class="comment">/* Try to get Media player device info XML file... */</span></div><div class="line"> <span class="comment">/* Loop over storages */</span></div><div class="line"> <span class="keywordflow">for</span> (storage = device-><a name="a23"></a><a class="code" href="structLIBMTP__mtpdevice__struct.html#ae6750437e5c4cd467287ed9bcaa404ab">storage</a>; storage != 0; storage = storage-><a name="a24"></a><a class="code" href="structLIBMTP__devicestorage__struct.html#ae663c1b5a8f3af8e7ecc11f865a8ed96">next</a>) {</div><div class="line"> <a name="_a25"></a><a class="code" href="structLIBMTP__file__struct.html">LIBMTP_file_t</a> *files;</div><div class="line"></div><div class="line"> <span class="comment">/* Get file listing for the root directory, no other dirs */</span></div><div class="line"> files = <a name="a26"></a><a class="code" href="group__files.html#ga2ffd5f4c9e1f306d5f65b891019f67b2">LIBMTP_Get_Files_And_Folders</a>(device,</div><div class="line"> storage-><a name="a27"></a><a class="code" href="structLIBMTP__devicestorage__struct.html#aee248c7a17f31d4864a67a5960e008ad">id</a>,</div><div class="line"> LIBMTP_FILES_AND_FOLDERS_ROOT);</div><div class="line"></div><div class="line"> <span class="keywordflow">if</span> (files != NULL) {</div><div class="line"> <a class="code" href="structLIBMTP__file__struct.html">LIBMTP_file_t</a> *file, *tmp;</div><div class="line"> file = files;</div><div class="line"> <span class="keywordflow">while</span> (file != NULL) {</div><div class="line"> <span class="keywordflow">if</span> (!strcmp(file-><a name="a28"></a><a class="code" href="structLIBMTP__file__struct.html#a2e92321a14e1604da9ab4648184d182d">filename</a>, <span class="stringliteral">"WMPInfo.xml"</span>) ||</div><div class="line"> !strcmp(file-><a class="code" href="structLIBMTP__file__struct.html#a2e92321a14e1604da9ab4648184d182d">filename</a>, <span class="stringliteral">"WMPinfo.xml"</span>) ||</div><div class="line"> !strcmp(file-><a class="code" href="structLIBMTP__file__struct.html#a2e92321a14e1604da9ab4648184d182d">filename</a>, <span class="stringliteral">"default-capabilities.xml"</span>)) {</div><div class="line"> <span class="keywordflow">if</span> (file-><a name="a29"></a><a class="code" href="structLIBMTP__file__struct.html#aaf61e9bb66af366adbc1ea834ffcb459">item_id</a> != 0) {</div><div class="line"> <span class="comment">/* Dump this file */</span></div><div class="line"> FILE *xmltmp = tmpfile();</div><div class="line"> <span class="keywordtype">int</span> tmpfiledescriptor = fileno(xmltmp);</div><div class="line"></div><div class="line"> <span class="keywordflow">if</span> (tmpfiledescriptor != -1) {</div><div class="line"> <span class="keywordtype">int</span> ret = <a name="a30"></a><a class="code" href="group__tracks.html#ga0836d80a1a78c604a805f0c347b8f236">LIBMTP_Get_Track_To_File_Descriptor</a>(device,</div><div class="line"> file-><a class="code" href="structLIBMTP__file__struct.html#aaf61e9bb66af366adbc1ea834ffcb459">item_id</a>,</div><div class="line"> tmpfiledescriptor,</div><div class="line"> NULL,</div><div class="line"> NULL);</div><div class="line"> <span class="keywordflow">if</span> (ret == 0) {</div><div class="line"> uint8_t *buf = NULL;</div><div class="line"> uint32_t readbytes;</div><div class="line"></div><div class="line"> buf = malloc(XML_BUFSIZE);</div><div class="line"> <span class="keywordflow">if</span> (buf == NULL) {</div><div class="line"> printf(<span class="stringliteral">"Could not allocate %08x bytes...\n"</span>, XML_BUFSIZE);</div><div class="line"> <a class="code" href="group__basic.html#ga682c81a83fa04b2caf5c962db1eaff82">LIBMTP_Dump_Errorstack</a>(device);</div><div class="line"> <a class="code" href="group__basic.html#ga6c05b927310ac830c149ae3eeae94047">LIBMTP_Clear_Errorstack</a>(device);</div><div class="line"> free(rawdevices);</div><div class="line"> <span class="keywordflow">return</span> 1;</div><div class="line"> }</div><div class="line"></div><div class="line"> lseek(tmpfiledescriptor, 0, SEEK_SET);</div><div class="line"> readbytes = read(tmpfiledescriptor, (<span class="keywordtype">void</span>*) buf, XML_BUFSIZE);</div><div class="line"></div><div class="line"> <span class="keywordflow">if</span> (readbytes >= 2 && readbytes < XML_BUFSIZE) {</div><div class="line"> fprintf(stdout, <span class="stringliteral">"\n%s file contents:\n"</span>, file-><a class="code" href="structLIBMTP__file__struct.html#a2e92321a14e1604da9ab4648184d182d">filename</a>);</div><div class="line"> dump_xml_fragment(buf, readbytes);</div><div class="line"> } <span class="keywordflow">else</span> {</div><div class="line"> perror(<span class="stringliteral">"Unable to read file"</span>);</div><div class="line"> <a class="code" href="group__basic.html#ga682c81a83fa04b2caf5c962db1eaff82">LIBMTP_Dump_Errorstack</a>(device);</div><div class="line"> <a class="code" href="group__basic.html#ga6c05b927310ac830c149ae3eeae94047">LIBMTP_Clear_Errorstack</a>(device);</div><div class="line"> }</div><div class="line"> free(buf);</div><div class="line"> } <span class="keywordflow">else</span> {</div><div class="line"> <a class="code" href="group__basic.html#ga682c81a83fa04b2caf5c962db1eaff82">LIBMTP_Dump_Errorstack</a>(device);</div><div class="line"> <a class="code" href="group__basic.html#ga6c05b927310ac830c149ae3eeae94047">LIBMTP_Clear_Errorstack</a>(device);</div><div class="line"> }</div><div class="line"> fclose(xmltmp);</div><div class="line"> }</div><div class="line"> }</div><div class="line"> }</div><div class="line"> tmp = file;</div><div class="line"> file = file-><a name="a31"></a><a class="code" href="structLIBMTP__file__struct.html#a220976ae777e294a0001ce8d781aaed6">next</a>;</div><div class="line"> <a name="a32"></a><a class="code" href="group__files.html#ga0fed9e491256fb80b323bdd030b162e9">LIBMTP_destroy_file_t</a>(tmp);</div><div class="line"> }</div><div class="line"> }</div><div class="line"> }</div><div class="line"> <a name="a33"></a><a class="code" href="group__basic.html#ga55377eb5a8ff6ce2b1a557356fe12039">LIBMTP_Release_Device</a>(device);</div><div class="line"> } <span class="comment">/* End For Loop */</span></div><div class="line"></div><div class="line"> free(rawdevices);</div><div class="line"></div><div class="line"> printf(<span class="stringliteral">"OK.\n"</span>);</div><div class="line"></div><div class="line"> <span class="keywordflow">return</span> 0;</div><div class="line">}</div></div><!-- fragment --> </div><!-- contents --> <!-- start footer part --> <hr class="footer"/><address class="footer"><small> Generated by  <a href="http://www.doxygen.org/index.html"> <img class="footer" src="doxygen.png" alt="doxygen"/> </a> 1.8.13 </small></address> </body> </html>