void BString::_Init(const char* src, int32 length) { fPrivateData = _Clone(src, length); if (fPrivateData == NULL) fPrivateData = _Clone(NULL, 0); }
/*! Makes this string writable, and resizes the buffer to \a length bytes (not including the terminating null). @param length The length of the new buffer in bytes. @param copy If true, the current string will be copied into the new string. */ status_t BString::_MakeWritable(int32 length, bool copy) { char* newData = NULL; if (atomic_get(&_ReferenceCount()) > 1) { // we might share our data with someone else if (copy) newData = _Clone(fPrivateData, length); else newData = _Allocate(length); if (newData == NULL) return B_NO_MEMORY; if (atomic_add(&_ReferenceCount(), -1) == 1) { // someone else left, we were the last owner _FreePrivateData(); } } else { // we don't share our data with someone else newData = _Resize(length); if (newData == NULL) return B_NO_MEMORY; } fPrivateData = newData; return B_OK; }
/*! Detaches this string from an eventually shared fPrivateData, ie. this makes this string writable. */ status_t BString::_MakeWritable() { if (atomic_get(&_ReferenceCount()) > 1) { // It might be shared, and this requires special treatment char* newData = _Clone(fPrivateData, Length()); if (atomic_add(&_ReferenceCount(), -1) == 1) { // someone else left, we were the last owner _FreePrivateData(); } if (newData == NULL) return B_NO_MEMORY; fPrivateData = newData; } return B_OK; }
/* nsIPrintSettings clone (); */ NS_IMETHODIMP nsPrintSettings::Clone(nsIPrintSettings **_retval) { NS_ENSURE_ARG_POINTER(_retval); return _Clone(_retval); }