135c4bbdfSmrg/* 235c4bbdfSmrg * Copyright (c) 1988, 1993 335c4bbdfSmrg * The Regents of the University of California. All rights reserved. 435c4bbdfSmrg * 535c4bbdfSmrg * Redistribution and use in source and binary forms, with or without 635c4bbdfSmrg * modification, are permitted provided that the following conditions 735c4bbdfSmrg * are met: 835c4bbdfSmrg * 1. Redistributions of source code must retain the above copyright 935c4bbdfSmrg * notice, this list of conditions and the following disclaimer. 1035c4bbdfSmrg * 2. Redistributions in binary form must reproduce the above copyright 1135c4bbdfSmrg * notice, this list of conditions and the following disclaimer in the 1235c4bbdfSmrg * documentation and/or other materials provided with the distribution. 1335c4bbdfSmrg * 4. Neither the name of the University nor the names of its contributors 1435c4bbdfSmrg * may be used to endorse or promote products derived from this software 1535c4bbdfSmrg * without specific prior written permission. 1635c4bbdfSmrg * 1735c4bbdfSmrg * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 1835c4bbdfSmrg * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1935c4bbdfSmrg * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2035c4bbdfSmrg * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 2135c4bbdfSmrg * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2235c4bbdfSmrg * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2335c4bbdfSmrg * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2435c4bbdfSmrg * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2535c4bbdfSmrg * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2635c4bbdfSmrg * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2735c4bbdfSmrg * SUCH DAMAGE. 2835c4bbdfSmrg */ 2935c4bbdfSmrg 3035c4bbdfSmrg#ifdef HAVE_DIX_CONFIG_H 3135c4bbdfSmrg#include <dix-config.h> 3235c4bbdfSmrg#endif 3335c4bbdfSmrg 3435c4bbdfSmrg#include <stddef.h> 3535c4bbdfSmrg#include <stdlib.h> 3635c4bbdfSmrg#include <string.h> 3735c4bbdfSmrg#include "os.h" 3835c4bbdfSmrg 3935c4bbdfSmrgchar * 4035c4bbdfSmrgstrndup(const char *str, size_t n) 4135c4bbdfSmrg{ 4235c4bbdfSmrg size_t len; 4335c4bbdfSmrg char *copy; 4435c4bbdfSmrg 4535c4bbdfSmrg for (len = 0; len < n && str[len]; len++) 4635c4bbdfSmrg continue; 4735c4bbdfSmrg 4835c4bbdfSmrg if ((copy = malloc(len + 1)) == NULL) 4935c4bbdfSmrg return (NULL); 5035c4bbdfSmrg memcpy(copy, str, len); 5135c4bbdfSmrg copy[len] = '\0'; 5235c4bbdfSmrg return (copy); 5335c4bbdfSmrg} 54