# Unsafe\_string and C\_NULL

**URL:** https://discourse.julialang.org/t/unsafe-string-and-c-null/8459
**Category:** General Usage
**Created:** [January 18, 2018, 5:40pm UTC](https://discourse.julialang.org/t/unsafe-string-and-c-null/8459 "2018-01-18T17:40:45Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![dmbates](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dmbates/32/44_2.png) [@dmbates](https://discourse.julialang.org/u/dmbates)
#### Post date: [January 18, 2018, 5:40pm UTC](https://discourse.julialang.org/t/unsafe-string-and-c-null/8459/1 "2018-01-18T17:40:45Z")

</div>

I just want to make sure I am not reinventing the wheel here. A library of C functions I am working with return `const char *` which I want to use as a Julia `String`. If the string should be empty they return `C_NULL`. I can easily write a Julia function

```julia
unsafe_string_allowing_NULL(ptr::Ptr{UInt8}) = ptr == C_NULL ? "" : unsafe_string(ptr)

```

but is there an existing idiom for this?

---

<div class="post-metadata">

### Author: ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)
#### Post date: [January 18, 2018, 5:51pm UTC](https://discourse.julialang.org/t/unsafe-string-and-c-null/8459/2 "2018-01-18T17:51:06Z")

</div>

> [@dmbates](#):
>
> is there an existing idiom for this?

Not that I know of.
