当前位置: 首页>>代码示例>>C++>>正文


C++ strerror_s函数代码示例

本文整理汇总了C++中strerror_s函数的典型用法代码示例。如果您正苦于以下问题:C++ strerror_s函数的具体用法?C++ strerror_s怎么用?C++ strerror_s使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了strerror_s函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: fatal_perror

void fatal_perror(const char *fmt, ...)
{
    va_list args;
    char *buf, buf2[4096];
    int errno_save = errno;
#ifdef _WIN32
    char errbuf[256];
#else
    char *errbuf;
#endif

#ifdef _WIN32
    strerror_s(errbuf, sizeof(errbuf), errno_save);
#else
    errbuf = strerror(errno_save);
#endif

    checkday();

    buf = log_gettimestamp();

    va_start(args, fmt);
    ircvsnprintf(buf2, sizeof(buf2), fmt, args);
    va_end(args);
    if (!NoLogs && logfile)
        fprintf(logfile, "%sFATAL: %s: %s\n", buf, buf2, errbuf);

    if (stderr)
        fprintf(stderr, "%sFATAL: %s: %s\n", buf, buf2, errbuf);

    if (servsock >= 0)
        denora_cmd_global(NULL, langstring(GLOBAL_FATAL_ERROR), buf2,
                          errbuf);
    exit(1);
}
开发者ID:wodim,项目名称:irc-hispano,代码行数:35,代码来源:log.c

示例2: bson_strerror_r

char *
bson_strerror_r (int err_code,  /* IN */
                 char *buf,     /* IN */
                 size_t buflen) /* IN */
{
   static const char *unknown_msg = "Unknown error";
   char *ret = NULL;

#if defined(_WIN32)
   if (strerror_s (buf, buflen, err_code) != 0) {
      ret = buf;
   }
#elif defined(__GNUC__) && defined(_GNU_SOURCE)
   ret = strerror_r (err_code, buf, buflen);
#else /* XSI strerror_r */
   if (strerror_r (err_code, buf, buflen) == 0) {
      ret = buf;
   }
#endif

   if (!ret) {
      bson_strncpy (buf, unknown_msg, buflen);
      ret = buf;
   }

   return ret;
}
开发者ID:acmorrow,项目名称:mongo-c-driver,代码行数:27,代码来源:bson-error.c

示例3: _accept

      void _accept()
      {
         #if _WIN32
            int client_length = sizeof(sockaddr_in);
         #else
            socklen_t client_length = sizeof(sockaddr_in);
         #endif

         _m_accepted_fd = ::accept(_m_socket_fd, (sockaddr *)&_m_client_address, &client_length);

         // -1 on failure
         if (_m_accepted_fd < 0)
         {
            std::string err = "Unable to connect to socket - error number: ";
            
            err += errno;
            
            err += " -- ";
            
            #if _WIN32
               char buffer[256];

               err += strerror_s(buffer, 256, errno);
            #else
               err += strerror(errno);
            #endif
            
            throw std::runtime_error(err);
         }
      }
开发者ID:jashook,项目名称:bandwidth,代码行数:30,代码来源:socket.hpp

示例4: compat53_strerror

static char* compat53_strerror (int en, char* buff, size_t sz) {
#if COMPAT53_HAVE_STRERROR_R
  /* use strerror_r here, because it's available on these specific platforms */
#if COMPAT53_HAVE_STRERROR_R_XSI
  /* XSI Compliant */
  strerror_r(en, buff, sz);
  return buff;
#else
  /* GNU-specific which returns const char* */
  return strerror_r(en, buff, sz);
#endif
#elif COMPAT53_HAVE_STRERROR_S
  /* for MSVC and other C11 implementations, use strerror_s
   * since it's provided by default by the libraries
   */
  strerror_s(buff, sz, en);
  return buff;
#else
  /* fallback, but
   * strerror is not guaranteed to be threadsafe due to modifying
   * errno itself and some impls not locking a static buffer for it
   * ... but most known systems have threadsafe errno: this might only change
   * if the locale is changed out from under someone while this function is being called
   */
  (void)buff;
  (void)sz;
  return strerror(en);
#endif
}
开发者ID:hishamhm,项目名称:dit,代码行数:29,代码来源:compat-5.3.c

示例5: errno_string

 std::string errno_string(int err)
 {
     char buffer[1024];
     if (strerror_s(buffer, sizeof(buffer), err))
         throw std::runtime_error("strerror_s failed");
     return buffer;
 }
开发者ID:wnewbery,项目名称:cpphttp,代码行数:7,代码来源:Net.cpp

示例6: thread_safe_strerror

        static std::string thread_safe_strerror(int errnum)
        {
#define ERRBUF_SIZE 512

#ifdef HAVE_STRERROR_S
            char buf[ERRBUF_SIZE] = { 0 };
            strerror_s(buf, ERRBUF_SIZE, errnum);
            return std::string(buf);
#else
#if (_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600) && !_GNU_SOURCE
            char buf[ERRBUF_SIZE] = { 0 };
            strerror_r(errnum, buf, ERRBUF_SIZE);
            return std::string(buf);
#elif _GNU_SOURCE
            /* GNU variant can return a pointer to static buffer instead of buf */
            char buf[ERRBUF_SIZE] = { 0 };
            return std::string(strerror_r(errnum, buf, ERRBUF_SIZE));
#else
            return std::string("An error occured with errnum ") +
                    std::to_string(errnum) +
                    ". Converting to the appropriate error message is disabled"
                    "in this instance of the png++ library.";
#endif
#endif

#undef ERRBUF_SIZE
        }
开发者ID:repetier,项目名称:Slic3r,代码行数:27,代码来源:error.hpp

示例7: get_userdata

static const char *file_stdio_ferrmsg(ALLEGRO_FILE *f)
{
   USERDATA *userdata = get_userdata(f);

   if (userdata->errnum == 0)
      return "";

   /* Note: at this time MinGW has neither strerror_r nor strerror_s. */
#if defined(ALLEGRO_HAVE_STRERROR_R)
   {
      int rc = strerror_r(userdata->errnum, userdata->errmsg,
         sizeof(userdata->errmsg));
      if (rc == 0) {
         return userdata->errmsg;
      }
   }
#endif

#if defined(ALLEGRO_HAVE_STRERROR_S)
   {
      errno_t rc = strerror_s(userdata->errmsg, sizeof(userdata->errmsg),
         userdata->errnum);
      if (rc == 0) {
         return userdata->errmsg;
      }
   }
#endif

   return "";
}
开发者ID:BorisCarvajal,项目名称:allegro5,代码行数:30,代码来源:file_stdio.c

示例8: win_strerror

/**
 * @brief: A secure version of Windows strerror.
 *
 * @param[in] errnum Error number.
 * @param[in] strErrMsg User-supplied message.
 *
 * @returns a pointer to the error-message string.
 * @see strerror on MSDN.
 */
char *
win_strerror(int errnum)
{
	static char buffer[MAXPATHLEN+1] = {'\0'};
	strerror_s(buffer, sizeof(buffer)-1, errnum);
	return buffer;
}
开发者ID:A9-William,项目名称:pbspro,代码行数:16,代码来源:util.c

示例9: throw_serialcom_exception

/*
* For C-standard/POSIX/OS specific/Custom/JNI errors, this function is called. It sets a pointer which is checked
* by java method when native function returns. If the pointer is set exception of class as set by this function is
* thrown.
*
* The type 1 indicates standard (C-standard/POSIX) error, 2 indicate custom (defined by this library)
* error, 3 indicates custom error with message string, 4 indicates error number specific to Windows OS.
*/
void throw_serialcom_exception(JNIEnv *env, int type, int error_code, const char *msg) {

	DWORD ret = -1;
	errno_t err_code = 0;
	char buffer[256];
	jclass serialComExceptionClass = NULL;

	(*env)->ExceptionClear(env);
	serialComExceptionClass = (*env)->FindClass(env, SCOMEXPCLASS);
	if ((serialComExceptionClass == NULL) || ((*env)->ExceptionOccurred(env) != NULL)) {
		(*env)->ExceptionClear(env);
		LOGE(E_FINDCLASSSCOMEXPSTR, FAILTHOWEXP);
		return;
	}

	switch (type) {
	case 4:
		/* Caller has given Windows error code */
		memset(buffer, '\0', sizeof(buffer));
		ret = FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
			NULL, error_code, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US),
			(LPSTR)&buffer, sizeof(buffer), NULL);
		if (ret == 0) {
			LOGEN(FAILTHOWEXP, "FormatMessageA()", GetLastError());
		}
		ret = (*env)->ThrowNew(env, serialComExceptionClass, buffer);
		if (ret < 0) {
			LOGE(FAILTHOWEXP, buffer);
		}
		break;
	case 3:
		/* Caller has given exception message explicitly */
		ret = (*env)->ThrowNew(env, serialComExceptionClass, msg);
		if (ret < 0) {
			LOGE(FAILTHOWEXP, msg);
		}
		break;
	case 2:
		/* Caller has given custom error code, need to get exception message corresponding to this code. */
		switch (error_code) {
		default: _snprintf_s(buffer, 256, 256, "%s\0", E_UNKNOWN);
		}
		ret = (*env)->ThrowNew(env, serialComExceptionClass, buffer);
		if (ret < 0) {
			LOGE(FAILTHOWEXP, buffer);
		}
		break;
	case 1:
		/* Caller has given posix error code, get error message corresponding to this code. */
		return;
	case 5:
		/* Caller has given <errno.h> error code for windows, get error message corresponding to this code. */
		memset(buffer, '\0', sizeof(buffer));
		err_code = strerror_s(buffer, sizeof(buffer), error_code);
		if (err_code != 0) {
			LOGEN(FAILTHOWEXP, "strerror_s()", err_code);
		}
	}
}
开发者ID:Tecsisa,项目名称:serial-communication-manager,代码行数:67,代码来源:scm_simpleio_exp.c

示例10: PrintLog

nfsstat3 CNFS3Prog::ProcedureWRITE(void)
{
    char *path;
    offset3 offset;
    count3 count;
    stable_how stable;
    opaque data;
    wcc_data file_wcc;
    writeverf3 verf;
    nfsstat3 stat;
    FILE *pFile;

    PrintLog("WRITE");
    path = GetPath();
    Read(&offset);
    Read(&count);
    Read(&stable);
    Read(&data);
    stat = CheckFile(path);

    file_wcc.before.attributes_follow = GetFileAttributesForNFS(path, &file_wcc.before.attributes);

    if (stat == NFS3_OK) {       
        pFile = _fsopen(path, "r+b", _SH_DENYWR);

        if (pFile != NULL) {
            _fseeki64(pFile, offset, SEEK_SET) ;
            count = fwrite(data.contents, sizeof(char), data.length, pFile);
            fclose(pFile);
        } else {
            char buffer[BUFFER_SIZE];
            errno_t errorNumber = errno;
            strerror_s(buffer, BUFFER_SIZE, errorNumber);
            PrintLog(buffer);

            if (errorNumber == 13) {
                stat = NFS3ERR_ACCES;
            } else {
                stat = NFS3ERR_IO;
            }
        }

        stable = FILE_SYNC;
        verf = 0;
    }

    file_wcc.after.attributes_follow = GetFileAttributesForNFS(path, &file_wcc.after.attributes);

    Write(&stat);
    Write(&file_wcc);

    if (stat == NFS3_OK) {
        Write(&count);
        Write(&stable);
        Write(&verf);
    }

    return stat;
}
开发者ID:philr,项目名称:winnfsd,代码行数:59,代码来源:NFS3Prog.cpp

示例11: err

char* err()
{
    static char buf[2048];
    strerror_s(buf, errno);
    // strerror(errno)

    return buf;
}
开发者ID:mildrock,项目名称:dummy,代码行数:8,代码来源:main.cpp

示例12: errno_str

std::string errno_str()
{
    char buffer[1024];
    errno_t e = strerror_s(buffer, sizeof(buffer), errno);
    if (e == 0) {
	return buffer;
    }
    return "errno:" + std::to_string(errno);
}
开发者ID:doj,项目名称:few,代码行数:9,代码来源:errno_str.cpp

示例13: __strerror

char* __strerror(int errnum) {
#ifdef _MSC_VER
    char errBuf[512];
    strerror_s(errBuf, errnum);
    return errBuf;
#else
    return strerror(errnum);
#endif
};
开发者ID:bell345,项目名称:write-to-bmp,代码行数:9,代码来源:crosscrtrepl.cpp

示例14: strerror_s

char *oscap_strerror_r(int errnum, char *buf, size_t buflen)
{
#ifdef OS_WINDOWS
	strerror_s(buf, buflen, errnum);
	return buf;
#else
	return strerror_r(errnum, buf, buflen);
#endif
}
开发者ID:jan-cerny,项目名称:openscap,代码行数:9,代码来源:util.c

示例15: errnoWithDescription

std::string errnoWithDescription(int errNumber) {
#if defined(_WIN32)
    if (errNumber == -1)
        errNumber = GetLastError();
#else
    if (errNumber < 0)
        errNumber = errno;
#endif

    char buf[kBuflen];
    char* msg{nullptr};

#if defined(__GNUC__) && defined(_GNU_SOURCE) && !(__ANDROID_API__ <= 22) && !defined(EMSCRIPTEN)
    msg = strerror_r(errNumber, buf, kBuflen);
#elif defined(_WIN32)

    LPWSTR errorText = nullptr;
    FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER |
                       FORMAT_MESSAGE_IGNORE_INSERTS,
                   nullptr,
                   errNumber,
                   0,
                   reinterpret_cast<LPWSTR>(&errorText),  // output
                   0,                                     // minimum size for output buffer
                   nullptr);

    if (errorText) {
        ON_BLOCK_EXIT([&errorText] { LocalFree(errorText); });
        std::string utf8ErrorText = toUtf8String(errorText);
        auto size = utf8ErrorText.find_first_of("\r\n");
        if (size == std::string::npos) {  // not found
            size = utf8ErrorText.length();
        }

        if (size >= kBuflen) {
            size = kBuflen - 1;
        }

        memcpy(buf, utf8ErrorText.c_str(), size);
        buf[size] = '\0';
        msg = buf;
    } else if (strerror_s(buf, kBuflen, errNumber) != 0) {
        msg = buf;
    }
#else /* XSI strerror_r */
    if (strerror_r(errNumber, buf, kBuflen) == 0) {
        msg = buf;
    }
#endif

    if (!msg) {
        return str::stream() << kUnknownMsg << errNumber;
    }

    return {msg};
}
开发者ID:ShaneHarvey,项目名称:mongo,代码行数:56,代码来源:errno_util.cpp


注:本文中的strerror_s函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。