Changeset 640ffe6 in mainline for uspace/app/sbi/src/os/posix.c


Ignore:
Timestamp:
2010-05-08T08:15:57Z (14 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
4039c77
Parents:
1317380 (diff), 051bc69a (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge from lp:~jsvoboda/helenos/sysel. New: cspan printing, boolean ops, enums, constructors etc.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/sbi/src/os/posix.c

    r1317380 r640ffe6  
    2929/** @file POSIX-specific code. */
    3030
     31#include <assert.h>
    3132#include <libgen.h>
    3233#include <stdio.h>
     
    7879}
    7980
     81/** Return slice (substring) of a string.
     82 *
     83 * Copies the specified range of characters from @a str and returns it
     84 * as a newly allocated string. @a start + @a length must be less than
     85 * or equal to the length of @a str.
     86 *
     87 * @param str           String
     88 * @param start         Index of first character (starting from zero).
     89 * @param length        Number of characters to copy.
     90 *
     91 * @return              Newly allocated string holding the slice.
     92 */
     93char *os_str_aslice(const char *str, size_t start, size_t length)
     94{
     95        char *slice;
     96
     97        assert(start + length <= strlen(str));
     98        slice = malloc(length + 1);
     99        if (slice == NULL) {
     100                printf("Memory allocation error.\n");
     101                exit(1);
     102        }
     103
     104        strncpy(slice, str + start, length);
     105        slice[length] = '\0';
     106
     107        return slice;
     108}
     109
    80110/** Compare two strings.
    81111 *
Note: See TracChangeset for help on using the changeset viewer.