---
title: withCString
framework: Kernel
role: symbol
role_heading: Type Method
platforms: [driverkit 19.0+, macOS 10.15+]
path: kernel/osstring/3180977-withcstring
---

# withCString

Allocates an OSString object with a copy of a c-string.

## Declaration

```occ
static OSStringPtr withCString(const char *cString);
```

```occ
static OSPtr<OSString> withCString(const char *cString);
```

## Parameters

- `cString`: Pointer to null terminated c-string. The string will be copied at the time of the call.

## Return Value

Return Value NULL on failure, otherwise the allocated OSString with reference count 1 to be released by the caller.

## See Also

### Creating a String

- [withCString](kernel/osstring/3433854-withcstring.md)
- [withCStringNoCopy](kernel/osstring/3180978-withcstringnocopy.md)
- [withString](kernel/osstring/3180979-withstring.md)
- [free](kernel/osstring/3180973-free.md)
