Next: , Previous: , Up: Particular Modules   [Contents][Index]

13.8 Quoting

Gnulib provides ‘quote’ and ‘quotearg’ modules to help with quoting text, such as file names, in messages to the user. Here’s an example of using ‘quote’:

#include <quote.h>
  error (0, errno, _("cannot change owner of %s"), quote (fname));

This differs from

  error (0, errno, _("cannot change owner of '%s'"), fname);

in that quote escapes unusual characters in fname, e.g., ‘'’ and control characters like ‘\n’.

However, a caveat: quote reuses the storage that it returns. Hence if you need more than one thing quoted at the same time, you need to use quote_n.

Also, the quote module is not suited for multithreaded applications. In that case, you have to use quotearg_alloc, defined in the ‘quotearg’ module, which is decidedly less convenient.