당신은 server/c.h
이를 찾을 수 있습니다 :
/* ----------------
* Variable-length datatypes all share the 'struct varlena' header.
*...
*/
struct varlena
{
char vl_len_[4]; /* Do not touch this field directly! */
char vl_dat[1];
};
#define VARHDRSZ ((int32) sizeof(int32))
/*
* These widely-used datatypes are just a varlena header and the data bytes.
* There is no terminating null or anything like that --- the data length is
* always VARSIZE(ptr) - VARHDRSZ.
*/
typedef struct varlena bytea;
typedef struct varlena text;
그래서 text
데이터 유형의 당신의 정의가있다. 주석이 오히려 중요한 부분을 참고 :
은 당신이 절대적으로 세그먼테이션 폴트 (segfault)와 같은 당신 않는 한 C 문자열로 fileName->data
을 치료하지 않을 것을 나타냅니다 그
같은 더 널 (null) 종료 또는 아무것도 없다. text
을 Null 종료 C 문자열로 변환하여 stat
으로 넘길 수있는 방법이 필요합니다. 그 기능은 다음과 같습니다 : text_to_cstring
.
내가 찾을 수 text_to_cstring
에 대한 유일한 문서는 this comment in the source입니다 : 또한 an example that uses it 있습니다
/*
* text_to_cstring
*
* Create a palloc'd, null-terminated C string from a text value.
*
* We support being passed a compressed or toasted text value.
* This is a bit bogus since such values shouldn't really be referred to as
* "text *", but it seems useful for robustness. If we didn't handle that
* case here, we'd need another routine that did, anyway.
*/
:
char *command;
/*...*/
/* Convert given text object to a C string */
command = text_to_cstring(sql);
/*...*/
pfree(command);
당신이 뭔가를 할 수 있어야한다
:
struct stat buf;
char *fileName = text_to_cstring(PG_GETARG_TEXT_P(0));
int i = stat(fileName, &buf);
pfree(fileName);
방법 '텍스트'가 정의 첫번째 builtins.h을 포함하는 것을 잊지 말아? 'text *'대신'char *'를 사용할 수 없습니까? –
나는 그것이 postgresql.h에 정의되어 있고 다음과 같이되어야한다고 생각한다 : typedef struct { int4 length; 문자 데이터 [1]; } 텍스트; –
분명히 보인다 :'fileName' 대신'fileName-> data' 만 참조하면된다. – netcoder