Convert existing Xprintf style calls to asprintf style

Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Reviewed-by: Jeremy Huddleston <jeremyhu@apple.com>
Reviewed-by: Mikhail Gusarov <dottedmag@dottedmag.net>
This commit is contained in:
Alan Coopersmith 2010-11-27 20:09:04 -08:00
parent c95c1d338f
commit 03e8bfa1d1
12 changed files with 88 additions and 59 deletions

View File

@ -200,7 +200,9 @@ device_added(LibHalContext *hal_ctx, const char *udi)
"config/hal: getting usb.product_id on %s " "config/hal: getting usb.product_id on %s "
"returned %04x\n", parent, usb_product); "returned %04x\n", parent, usb_product);
if (usb_vendor && usb_product) if (usb_vendor && usb_product)
attrs.usb_id = Xprintf("%04x:%04x", usb_vendor, usb_product); if (asprintf(&attrs.usb_id, "%04x:%04x", usb_vendor, usb_product)
== -1)
attrs.usb_id = NULL;
free(parent); free(parent);
} }

View File

@ -108,8 +108,10 @@ device_added(struct udev_device *udev_device)
/* construct USB ID in lowercase hex - "0000:ffff" */ /* construct USB ID in lowercase hex - "0000:ffff" */
if (product && sscanf(product, "%*x/%4x/%4x/%*x", &usb_vendor, &usb_model) == 2) { if (product && sscanf(product, "%*x/%4x/%4x/%*x", &usb_vendor, &usb_model) == 2) {
attrs.usb_id = Xprintf("%04x:%04x", usb_vendor, usb_model); if (asprintf(&attrs.usb_id, "%04x:%04x", usb_vendor, usb_model)
if (attrs.usb_id) == -1)
attrs.usb_id = NULL;
else
LOG_PROPERTY(path, "PRODUCT", product); LOG_PROPERTY(path, "PRODUCT", product);
} }
} }
@ -127,9 +129,10 @@ device_added(struct udev_device *udev_device)
LOG_PROPERTY(path, "ID_INPUT.tags", tags_prop); LOG_PROPERTY(path, "ID_INPUT.tags", tags_prop);
attrs.tags = xstrtokenize(tags_prop, ","); attrs.tags = xstrtokenize(tags_prop, ",");
config_info = Xprintf("udev:%s", syspath); if (asprintf(&config_info, "udev:%s", syspath) == -1) {
if (!config_info) config_info = NULL;
goto unwind; goto unwind;
}
if (device_is_duplicate(config_info)) { if (device_is_duplicate(config_info)) {
LogMessage(X_WARNING, "config/udev: device %s already added. " LogMessage(X_WARNING, "config/udev: device %s already added. "
@ -217,8 +220,7 @@ device_removed(struct udev_device *device)
char *value; char *value;
const char *syspath = udev_device_get_syspath(device); const char *syspath = udev_device_get_syspath(device);
value = Xprintf("udev:%s", syspath); if (asprintf(&value, "udev:%s", syspath) == -1)
if (!value)
return; return;
remove_devices("udev", value); remove_devices("udev", value);

View File

@ -1817,7 +1817,9 @@ SetDefaultFontPath(char *path)
start = end; start = end;
} }
if (!start) { if (!start) {
temp_path = Xprintf("%s%sbuilt-ins", path, *path ? "," : ""); if (asprintf(&temp_path, "%s%sbuilt-ins", path, *path ? "," : "")
== -1)
temp_path = NULL;
} else { } else {
temp_path = strdup(path); temp_path = strdup(path);
} }

View File

@ -297,8 +297,8 @@ copyScreen(confScreenPtr oscreen, GDevPtr odev, int i, char *driver)
} }
memcpy(cptr, odev, sizeof(GDevRec)); memcpy(cptr, odev, sizeof(GDevRec));
cptr->identifier = Xprintf("Autoconfigured Video Device %s", driver); if (asprintf(&cptr->identifier, "Autoconfigured Video Device %s", driver)
if (!cptr->identifier) { == -1) {
free(cptr); free(cptr);
free(nscreen); free(nscreen);
return FALSE; return FALSE;

View File

@ -585,12 +585,11 @@ configFiles(XF86ConfFilesPtr fileconf)
else if (fileconf && fileconf->file_fontpath) { else if (fileconf && fileconf->file_fontpath) {
pathFrom = X_CONFIG; pathFrom = X_CONFIG;
if (xf86Info.useDefaultFontPath) { if (xf86Info.useDefaultFontPath) {
defaultFontPath = Xprintf("%s%s%s", if (asprintf(&defaultFontPath, "%s%s%s", fileconf->file_fontpath,
fileconf->file_fontpath, *temp_path ? "," : "", temp_path) == -1)
*temp_path ? "," : "", temp_path); defaultFontPath = NULL;
if (defaultFontPath != NULL) { else
must_copy = FALSE; must_copy = FALSE;
}
} }
else else
defaultFontPath = fileconf->file_fontpath; defaultFontPath = fileconf->file_fontpath;

View File

@ -1193,9 +1193,13 @@ xf86VIDrvMsgVerb(InputInfoPtr dev, MessageType type, int verb, const char *forma
{ {
char *msg; char *msg;
msg = Xprintf("%s: %s: %s", dev->drv->driverName, dev->name, format); if (asprintf(&msg, "%s: %s: %s", dev->drv->driverName, dev->name, format)
LogVMessageVerb(type, verb, msg, args); == -1) {
free(msg); LogVMessageVerb(type, verb, "%s", args);
} else {
LogVMessageVerb(type, verb, msg, args);
free(msg);
}
} }
/* Print input driver message, with verbose level specified directly */ /* Print input driver message, with verbose level specified directly */

View File

@ -132,8 +132,8 @@ xf86SetModeDefaultName(DisplayModePtr mode)
free(mode->name); free(mode->name);
mode->name = XNFprintf("%dx%d%s", mode->HDisplay, mode->VDisplay, XNFasprintf(&mode->name, "%dx%d%s", mode->HDisplay, mode->VDisplay,
interlaced ? "i" : ""); interlaced ? "i" : "");
} }
/* /*

View File

@ -221,9 +221,10 @@ if (fDebugProcMsg) \
{ \ { \
char *pszTemp; \ char *pszTemp; \
int iLength; \ int iLength; \
pszTemp = Xprintf (str, ##__VA_ARGS__); \ if (asprintf (&pszTemp, str, ##__VA_ARGS__) != -1) { \
MessageBox (NULL, pszTemp, szFunctionName, MB_OK); \ MessageBox (NULL, pszTemp, szFunctionName, MB_OK); \
free(pszTemp); \ free (pszTemp); \
} \
} }
#else #else
#define DEBUG_MSG(str,...) #define DEBUG_MSG(str,...)

View File

@ -341,11 +341,10 @@ winExitDlgProc (HWND hDialog, UINT message,
winInitDialog (hDialog); winInitDialog (hDialog);
/* Format the connected clients string */ /* Format the connected clients string */
pszConnectedClients = Xprintf (CONNECTED_CLIENTS_FORMAT, if (asprintf (&pszConnectedClients, CONNECTED_CLIENTS_FORMAT,
(s_pScreenPriv->iConnectedClients == 1) ? "is" : "are", (s_pScreenPriv->iConnectedClients == 1) ? "is" : "are",
s_pScreenPriv->iConnectedClients, s_pScreenPriv->iConnectedClients,
(s_pScreenPriv->iConnectedClients == 1) ? "" : "s"); (s_pScreenPriv->iConnectedClients == 1) ? "" : "s") == -1)
if (!pszConnectedClients)
return TRUE; return TRUE;

View File

@ -101,12 +101,15 @@ winMessageBoxF (const char *pszError, UINT uType, ...)
char * pszErrorF = NULL; char * pszErrorF = NULL;
char * pszMsgBox = NULL; char * pszMsgBox = NULL;
va_list args; va_list args;
int size;
va_start(args, uType); va_start(args, uType);
pszErrorF = Xvprintf(pszError, args); size = vasprintf (&pszErrorF, pszError, args);
va_end(args); va_end(args);
if (!pszErrorF) if (size == -1) {
pszErrorF = NULL;
goto winMessageBoxF_Cleanup; goto winMessageBoxF_Cleanup;
}
#define MESSAGEBOXF \ #define MESSAGEBOXF \
"%s\n" \ "%s\n" \
@ -117,15 +120,18 @@ winMessageBoxF (const char *pszError, UINT uType, ...)
"XWin was started with the following command-line:\n\n" \ "XWin was started with the following command-line:\n\n" \
"%s\n" "%s\n"
pszMsgBox = Xprintf (MESSAGEBOXF, size = asprintf (&pszMsgBox, MESSAGEBOXF,
pszErrorF, XVENDORNAME, pszErrorF, XVENDORNAME,
XORG_VERSION_MAJOR, XORG_VERSION_MINOR, XORG_VERSION_PATCH, XORG_VERSION_SNAP, XORG_VERSION_CURRENT, XORG_VERSION_MAJOR, XORG_VERSION_MINOR, XORG_VERSION_PATCH,
BUILDERADDR, XORG_VERSION_SNAP, XORG_VERSION_CURRENT,
BUILDERSTRING, BUILDERADDR,
g_pszCommandLine); BUILDERSTRING,
g_pszCommandLine);
if (!pszMsgBox) if (size == -1) {
pszMsgBox = NULL;
goto winMessageBoxF_Cleanup; goto winMessageBoxF_Cleanup;
}
/* Display the message box string */ /* Display the message box string */
MessageBox (NULL, MessageBox (NULL,

View File

@ -156,34 +156,45 @@ char tmpname[PATH_MAX];
#endif #endif
if (XkbBaseDirectory!=NULL) { if (XkbBaseDirectory!=NULL) {
if ((list->pattern[what][0]=='*')&&(list->pattern[what][1]=='\0')) { if ((list->pattern[what][0]=='*')&&(list->pattern[what][1]=='\0')) {
buf = Xprintf("%s/%s.dir",XkbBaseDirectory,componentDirs[what]); if (asprintf(&buf, "%s/%s.dir", XkbBaseDirectory,
in= fopen(buf,"r"); componentDirs[what]) == -1)
buf = NULL;
else
in = fopen(buf,"r");
} }
if (!in) { if (!in) {
haveDir= FALSE; haveDir= FALSE;
free(buf); free(buf);
buf = Xprintf( if (asprintf
"'%s/xkbcomp' '-R%s/%s' -w %ld -l -vlfhpR '%s'" W32_tmparg, (&buf,
XkbBinDirectory,XkbBaseDirectory,componentDirs[what],(long) "'%s/xkbcomp' '-R%s/%s' -w %ld -l -vlfhpR '%s'" W32_tmparg,
((xkbDebugFlags<2)?1:((xkbDebugFlags>10)?10:xkbDebugFlags)), XkbBinDirectory, XkbBaseDirectory, componentDirs[what],
file W32_tmpfile (long) ((xkbDebugFlags < 2) ? 1 :
); ((xkbDebugFlags > 10) ? 10 : xkbDebugFlags)),
file W32_tmpfile
) == -1)
buf = NULL;
} }
} }
else { else {
if ((list->pattern[what][0]=='*')&&(list->pattern[what][1]=='\0')) { if ((list->pattern[what][0]=='*')&&(list->pattern[what][1]=='\0')) {
buf = Xprintf("%s.dir",componentDirs[what]); if (asprintf(&buf, "%s.dir", componentDirs[what]) == -1)
in= fopen(buf,"r"); buf = NULL;
else
in = fopen(buf,"r");
} }
if (!in) { if (!in) {
haveDir= FALSE; haveDir= FALSE;
free(buf); free(buf);
buf = Xprintf( if (asprintf
"xkbcomp -R%s -w %ld -l -vlfhpR '%s'" W32_tmparg, (&buf,
componentDirs[what],(long) "xkbcomp -R%s -w %ld -l -vlfhpR '%s'" W32_tmparg,
((xkbDebugFlags<2)?1:((xkbDebugFlags>10)?10:xkbDebugFlags)), componentDirs[what],
file W32_tmpfile (long) ((xkbDebugFlags < 2) ? 1 :
); ((xkbDebugFlags > 10) ? 10 : xkbDebugFlags)),
file W32_tmpfile
) == -1)
buf = NULL;
} }
} }
status= Success; status= Success;

View File

@ -210,7 +210,8 @@ XkbDDXCompileKeymapByNames( XkbDescPtr xkb,
#endif #endif
if (XkbBaseDirectory != NULL) { if (XkbBaseDirectory != NULL) {
xkbbasedirflag = Xprintf("\"-R%s\"", XkbBaseDirectory); if (asprintf(&xkbbasedirflag, "\"-R%s\"", XkbBaseDirectory) == -1)
xkbbasedirflag = NULL;
} }
if (XkbBinDirectory != NULL) { if (XkbBinDirectory != NULL) {
@ -225,14 +226,16 @@ XkbDDXCompileKeymapByNames( XkbDescPtr xkb,
} }
} }
buf = Xprintf("\"%s%sxkbcomp\" -w %d %s -xkm \"%s\" " if (asprintf(&buf,
"\"%s%sxkbcomp\" -w %d %s -xkm \"%s\" "
"-em1 %s -emp %s -eml %s \"%s%s.xkm\"", "-em1 %s -emp %s -eml %s \"%s%s.xkm\"",
xkbbindir, xkbbindirsep, xkbbindir, xkbbindirsep,
( (xkbDebugFlags < 2) ? 1 : ((xkbDebugFlags < 2) ? 1 :
((xkbDebugFlags > 10) ? 10 : (int)xkbDebugFlags) ), ((xkbDebugFlags > 10) ? 10 : (int) xkbDebugFlags)),
xkbbasedirflag ? xkbbasedirflag : "", xkmfile, xkbbasedirflag ? xkbbasedirflag : "", xkmfile,
PRE_ERROR_MSG, ERROR_PREFIX, POST_ERROR_MSG1, PRE_ERROR_MSG, ERROR_PREFIX, POST_ERROR_MSG1,
xkm_output_dir, keymap); xkm_output_dir, keymap) == -1)
buf = NULL;
free(xkbbasedirflag); free(xkbbasedirflag);