diff --git a/camlibs/ptp2/ChangeLog b/camlibs/ptp2/ChangeLog index 4b5541ac8..f1a4d74e9 100644 --- a/camlibs/ptp2/ChangeLog +++ b/camlibs/ptp2/ChangeLog @@ -1,3 +1,8 @@ +2006-09-13 Marcus Meissner + + * ptp.[ch]: formatstore function (from libmtp). + * library.c: fixed iconv() usage for non glibc etc (from libmtp). + 2006-09-11 Marcus Meissner * library.c: Added iRIver T10 2GB model. diff --git a/camlibs/ptp2/library.c b/camlibs/ptp2/library.c index 4e0a61006..74bd70725 100644 --- a/camlibs/ptp2/library.c +++ b/camlibs/ptp2/library.c @@ -50,6 +50,23 @@ # define N_(String) (String) #endif +/* + * On MacOS (Darwin) and *BSD we're not using glibc, but libiconv. + * glibc knows that UCS-2 is to be in the local machine endianness, + * whereas libiconv does not. So we construct this macro to get + * things right. Reportedly, glibc 2.1.3 has a bug so that UCS-2 + * is always bigendian though, we would need to work around that + * too... + */ +#ifndef __GLIBC__ +#define UCS_2_INTERNAL "UCS-2-INTERNAL" +#else +#if (__GLIBC__ == 2 && __GLIBC_MINOR__ <= 1 ) +#error "Too old glibc. This versions iconv() implementation cannot be trusted." +#endif +#define UCS_2_INTERNAL "UCS-2" +#endif + #include "ptp.h" #include "ptp-bugs.h" #include "ptp-private.h" @@ -3469,8 +3486,8 @@ camera_init (Camera *camera, GPContext *context) curloc = nl_langinfo (CODESET); if (!curloc) curloc="UTF-8"; - camera->pl->params.cd_ucs2_to_locale = iconv_open(curloc, "UCS-2"); - camera->pl->params.cd_locale_to_ucs2 = iconv_open("UCS-2", curloc); + camera->pl->params.cd_ucs2_to_locale = iconv_open(curloc, UCS_2_INTERNAL); + camera->pl->params.cd_locale_to_ucs2 = iconv_open(UCS_2_INTERNAL, curloc); if ((camera->pl->params.cd_ucs2_to_locale == (iconv_t) -1) || (camera->pl->params.cd_locale_to_ucs2 == (iconv_t) -1)) { gp_log (GP_LOG_ERROR, "iconv", "Failed to create iconv converter.\n"); diff --git a/camlibs/ptp2/ptp.c b/camlibs/ptp2/ptp.c index 62c518cad..a1f7d67af 100644 --- a/camlibs/ptp2/ptp.c +++ b/camlibs/ptp2/ptp.c @@ -679,6 +679,28 @@ ptp_getstorageinfo (PTPParams* params, uint32_t storageid, return ret; } +/** + * ptp_formatstore: + * params: PTPParams* + * storageid - StorageID + * + * Formats the storage on the device. + * + * Return values: Some PTP_RC_* code. + **/ +uint16_t +ptp_formatstore (PTPParams* params, uint32_t storageid) +{ + PTPContainer ptp; + + PTP_CNT_INIT(ptp); + ptp.Code=PTP_OC_FormatStore; + ptp.Param1=storageid; + ptp.Param2=PTP_FST_Undefined; + ptp.Nparam=2; + return ptp_transaction(params, &ptp, PTP_DP_NODATA, 0, NULL, NULL); +} + /** * ptp_getobjecthandles: * params: PTPParams* diff --git a/camlibs/ptp2/ptp.h b/camlibs/ptp2/ptp.h index a225ab8d5..665d61f89 100644 --- a/camlibs/ptp2/ptp.h +++ b/camlibs/ptp2/ptp.h @@ -1145,6 +1145,7 @@ uint16_t ptp_closesession (PTPParams *params); uint16_t ptp_getstorageids (PTPParams* params, PTPStorageIDs* storageids); uint16_t ptp_getstorageinfo (PTPParams* params, uint32_t storageid, PTPStorageInfo* storageinfo); +uint16_t ptp_formatstore (PTPParams* params, uint32_t storageid); uint16_t ptp_getobjecthandles (PTPParams* params, uint32_t storage, uint32_t objectformatcode,