~ubuntu-branches/ubuntu/saucy/u-boot/saucy

« back to all changes in this revision

Viewing changes to lib/string.c

  • Committer: Package Import Robot
  • Author(s): Clint Adams
  • Date: 2012-05-01 18:07:19 UTC
  • mfrom: (16.1.23 sid)
  • Revision ID: package-import@ubuntu.com-20120501180719-rjntk3287im4a0ns
Tags: 2012.04.01-1
* New upstream version.
  - Update mipsel-native-endianness.diff.
  - Update no-error-on-set-but-unused-variables.diff (partially merged).
  - Drop kirkwood_spi-irq_mask.diff (merged).
  - Drop kirkwood-disable-l2c.diff (merged).

Show diffs side-by-side

added added

removed removed

Lines of Context:
214
214
}
215
215
#endif
216
216
 
 
217
 
 
218
/**
 
219
 * skip_spaces - Removes leading whitespace from @str.
 
220
 * @str: The string to be stripped.
 
221
 *
 
222
 * Returns a pointer to the first non-whitespace character in @str.
 
223
 */
 
224
char *skip_spaces(const char *str)
 
225
{
 
226
        while (isspace(*str))
 
227
                ++str;
 
228
        return (char *)str;
 
229
}
 
230
 
 
231
/**
 
232
 * strim - Removes leading and trailing whitespace from @s.
 
233
 * @s: The string to be stripped.
 
234
 *
 
235
 * Note that the first trailing whitespace is replaced with a %NUL-terminator
 
236
 * in the given string @s. Returns a pointer to the first non-whitespace
 
237
 * character in @s.
 
238
 */
 
239
char *strim(char *s)
 
240
{
 
241
        size_t size;
 
242
        char *end;
 
243
 
 
244
        s = skip_spaces(s);
 
245
        size = strlen(s);
 
246
        if (!size)
 
247
                return s;
 
248
 
 
249
        end = s + size - 1;
 
250
        while (end >= s && isspace(*end))
 
251
                end--;
 
252
        *(end + 1) = '\0';
 
253
 
 
254
        return s;
 
255
}
217
256
#ifndef __HAVE_ARCH_STRLEN
218
257
/**
219
258
 * strlen - Find the length of a string