tmpnam_s, _wtmpnam_s

임시 파일을 만드는 데 사용할 수 있는 이름을 생성합니다. 이러한 함수는 CRT의 보안 기능에 설명된 대로 향상된 보안 기능의 tmpnam 버전입니다_wtmpnam.

구문

errno_t tmpnam_s(
   char * str,
   size_t sizeInChars
);
errno_t _wtmpnam_s(
   wchar_t *str,
   size_t sizeInChars
);
template <size_t size>
errno_t tmpnam_s(
   char (&str)[size]
); // C++ only
template <size_t size>
errno_t _wtmpnam_s(
   wchar_t (&str)[size]
); // C++ only

매개 변수

str
[out] 생성된 이름을 보유하는 포인터입니다.

sizeInChars
[in] 버퍼의 크기(문자)입니다.

반환 값

이 두 함수는 정상적으로 실행되면 0을 반환하고 오류 시에는 오류 번호를 반환합니다.

오류 조건

str sizeInChars 반환 값 str의 내용
NULL any EINVAL 수정 안 됨
NULL 아님(올바른 메모리를 가리킴) 너무 짧음 ERANGE 수정 안 됨

이 경우 str 매개 변수 유효성 검사에 설명된 대로 잘못된 매개 변수 처리기가 호출NULL됩니다. 계속해서 실행하도록 허용된 경우 이러한 함수는 errnoEINVAL로 설정하고 EINVAL을 반환합니다.

설명

이러한 각 함수는 현재 존재하지 않는 파일의 이름을 반환합니다. tmpnam_s 에서 반환한 지정된 Windows 임시 디렉터리에서 고유한 이름을 반환 GetTempPathW합니다. 파일 이름 앞에 백슬래시가 추가되고 경로 정보(예: \fname21경로 정보가 없는 경우)는 현재 작업 디렉터리에 이름이 유효하다는 것을 나타냅니다.

tmpnam_s의 경우에는 생성된 이 파일 이름을 str에 저장할 수 있습니다. tmpnam_s에서 반환하는 문자열의 최대 길이는 STDIO.H에 정의된 L_tmpnam_s입니다. strNULL이면 tmpnam_s은 결과를 내부 정적 버퍼에 유지합니다. 따라서 모든 후속 호출에서는 이 값을 제거합니다. 생성되는 tmpnam_s 이름은 프로그램에서 생성한 파일 이름과 첫 번째 호출 tmpnam_s후 STDIO의 경우 base 32(.1-.1vvvvvvu TMP_MAX_S )의 순차적 숫자의 파일 확장명으로 구성됩니다. H는 )입니다 INT_MAX.

tmpnam_s는 운영 체제에서 가져온 OEM 코드 페이지에 따라 멀티바이트 문자 시퀀스를 인식하여 멀티바이트 문자열 인수를 자동으로 적절히 처리합니다. _wtmpnam_stmpnam_s의 와이드 문자 버전이고, _wtmpnam_s의 인수와 반환 값은 와이드 문자 문자열입니다. _wtmpnam_s 멀티 tmpnam_s 바이트 문자열을 _wtmpnam_s 처리하지 않는다는 점을 제외하고 동일하게 동작합니다.

C++에서는 템플릿 오버로드를 통해 이러한 함수를 사용하는 것이 더욱 간단해집니다. 오버로드는 버퍼 길이를 자동으로 유추할 수 있으므로 크기 인수를 지정할 필요가 없습니다. 자세한 내용은 보안 템플릿 오버로드를 참조 하세요.

기본적으로 이 함수의 전역 상태는 애플리케이션으로 범위가 지정됩니다. 이 동작을 변경하려면 CRT의 전역 상태를 참조하세요.

일반 텍스트 루틴 매핑

TCHAR.H 루틴 _UNICODE 정의 _MBCS 되지 않음 _MBCS 정의 _UNICODE 정의
_ttmpnam_s tmpnam_s tmpnam_s _wtmpnam_s

요구 사항

루틴에서 반환된 값 필수 헤더
tmpnam_s <stdio.h>
_wtmpnam_s <stdio.h> 또는 <wchar.h>

호환성에 대한 자세한 내용은 호환성을 참조하세요.

예시

// crt_tmpnam_s.c
// This program uses tmpnam_s to create a unique filename in the
// current working directory.
//

#include <stdio.h>
#include <stdlib.h>

int main( void )
{
   char name1[L_tmpnam_s];
   errno_t err;
   int i;

   for (i = 0; i < 15; i++)
   {
      err = tmpnam_s( name1, L_tmpnam_s );
      if (err)
      {
         printf("Error occurred creating unique filename.\n");
         exit(1);
      }
      else
      {
         printf( "%s is safe to use as a temporary file.\n", name1 );
      }
   }
}
C:\Users\LocalUser\AppData\Local\Temp\u19q8.0 is safe to use as a temporary file.
C:\Users\LocalUser\AppData\Local\Temp\u19q8.1 is safe to use as a temporary file.
C:\Users\LocalUser\AppData\Local\Temp\u19q8.2 is safe to use as a temporary file.
C:\Users\LocalUser\AppData\Local\Temp\u19q8.3 is safe to use as a temporary file.
C:\Users\LocalUser\AppData\Local\Temp\u19q8.4 is safe to use as a temporary file.
C:\Users\LocalUser\AppData\Local\Temp\u19q8.5 is safe to use as a temporary file.
C:\Users\LocalUser\AppData\Local\Temp\u19q8.6 is safe to use as a temporary file.
C:\Users\LocalUser\AppData\Local\Temp\u19q8.7 is safe to use as a temporary file.
C:\Users\LocalUser\AppData\Local\Temp\u19q8.8 is safe to use as a temporary file.
C:\Users\LocalUser\AppData\Local\Temp\u19q8.9 is safe to use as a temporary file.
C:\Users\LocalUser\AppData\Local\Temp\u19q8.a is safe to use as a temporary file.
C:\Users\LocalUser\AppData\Local\Temp\u19q8.b is safe to use as a temporary file.
C:\Users\LocalUser\AppData\Local\Temp\u19q8.c is safe to use as a temporary file.
C:\Users\LocalUser\AppData\Local\Temp\u19q8.d is safe to use as a temporary file.
C:\Users\LocalUser\AppData\Local\Temp\u19q8.e is safe to use as a temporary file.

참고 항목

스트림 I/O
_getmbcp
malloc
_setmbcp
tmpfile_s