简体   繁体   English

我将如何使用 c 语言将文件名的路径传递给 void *buffer?

[英]how will i pass the path of a file name to void *buffer using c language?

implementing ProcessRequest and wants to copy data into buffer to return to the caller实现 ProcessRequest 并希望将数据复制到缓冲区以返回给调用者

The function signature is he following :函数签名如下:
int ProcessRequest(HCST hCST, void *buffer, short tag, short status)

path name of the file is stored in char src [40] ;文件的路径名存储在char src [40]

You need this :你需要这个 :

int ProcessRequest(int hCST, void *buffer, short tag, short status)
{
  // stub function 
  static char test[] = "Test";
  strcpy(buffer, test);
  return 0;
}

...
char src [40];
...
ProcessRequest(myhCST, src, mytag, mystatus);
/* now src contains "Test" */

This code is very simple and unsafe because ProcessRequest doesn't know the size of buffer and hence may potentially overwrite past the end of buffer .这段代码非常简单且不安全,因为ProcessRequest不知道buffer的大小,因此可能会在buffer结束后覆盖。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM