File: bindc_07.c

package info (click to toggle)
lfortran 0.59.0-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 56,736 kB
  • sloc: cpp: 168,052; f90: 74,272; python: 17,537; ansic: 7,705; yacc: 2,345; sh: 1,334; fortran: 895; makefile: 37; javascript: 15
file content (49 lines) | stat: -rw-r--r-- 1,452 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
// Dummy getcwd function that mimics the real getcwd behavior
char* getcwd_dummy(char* buf, size_t size) {
    const char* dummy_path = "/home/user/test/directory";
    size_t path_len = strlen(dummy_path);
    
    if (buf == NULL) {
        printf("ERROR: Received NULL buffer pointer!\n");
        return NULL;
    }
    
    if (size <= path_len) {
        printf("ERROR: Buffer too small! Need %zu, got %zu\n", path_len + 1, size);
        return NULL;
    }
    
    // Debug: Print what we received
    printf("C function received:\n");
    printf("  - Buffer pointer: %p\n", (void*)buf);
    printf("  - Buffer size: %zu\n", size);
    
    // Copy the dummy path to the buffer
    strcpy(buf, dummy_path);
    
    printf("  - Copied path: '%s'\n", buf);
    printf("  - Path length: %zu\n", strlen(buf));
    
    return buf;  // Return the buffer pointer on success
}

char* test_char_array(char* buffer, int len) {
    printf("C test_char_array received:\n");
    printf("  - Buffer pointer: %p\n", (void*)buffer);
    printf("  - Length parameter: %d\n", len);
    
    if (buffer == NULL) {
        printf("  - ERROR: NULL buffer!\n");
        return NULL;
    }
    
    // Write a test string
    const char* test_str = "Hello from C!";
    strncpy(buffer, test_str, len - 1);
    buffer[len - 1] = '\0';
    printf("  - Wrote to buffer: '%s'\n", buffer);
    return buffer;
}