@@ -159,74 +159,112 @@ typedef XLogLongPageHeaderData *XLogLongPageHeader;
159159#define XLOG_FNAME_LEN 24
160160
161161/*
162- * Generate a WAL segment file name. Do not use this macro in a helper
162+ * Generate a WAL segment file name. Do not use this function in a helper
163163 * function allocating the result generated.
164164 */
165- #define XLogFileName (fname , tli , logSegNo , wal_segsz_bytes ) \
166- snprintf(fname, MAXFNAMELEN, "%08X%08X%08X", tli, \
167- (uint32) ((logSegNo) / XLogSegmentsPerXLogId(wal_segsz_bytes)), \
168- (uint32) ((logSegNo) % XLogSegmentsPerXLogId(wal_segsz_bytes)))
165+ static inline void
166+ XLogFileName (char * fname , TimeLineID tli , XLogSegNo logSegNo , int wal_segsz_bytes )
167+ {
168+ snprintf (fname , MAXFNAMELEN , "%08X%08X%08X" , tli ,
169+ (uint32 ) (logSegNo / XLogSegmentsPerXLogId (wal_segsz_bytes )),
170+ (uint32 ) (logSegNo % XLogSegmentsPerXLogId (wal_segsz_bytes )));
171+ }
169172
170- #define XLogFileNameById (fname , tli , log , seg ) \
171- snprintf(fname, MAXFNAMELEN, "%08X%08X%08X", tli, log, seg)
173+ static inline void
174+ XLogFileNameById (char * fname , TimeLineID tli , uint32 log , uint32 seg )
175+ {
176+ snprintf (fname , MAXFNAMELEN , "%08X%08X%08X" , tli , log , seg );
177+ }
172178
173- #define IsXLogFileName (fname ) \
174- (strlen(fname) == XLOG_FNAME_LEN && \
175- strspn(fname, "0123456789ABCDEF") == XLOG_FNAME_LEN)
179+ static inline bool
180+ IsXLogFileName (const char * fname )
181+ {
182+ return (strlen (fname ) == XLOG_FNAME_LEN && \
183+ strspn (fname , "0123456789ABCDEF" ) == XLOG_FNAME_LEN );
184+ }
176185
177186/*
178187 * XLOG segment with .partial suffix. Used by pg_receivewal and at end of
179188 * archive recovery, when we want to archive a WAL segment but it might not
180189 * be complete yet.
181190 */
182- #define IsPartialXLogFileName (fname ) \
183- (strlen(fname) == XLOG_FNAME_LEN + strlen(".partial") && \
184- strspn(fname, "0123456789ABCDEF") == XLOG_FNAME_LEN && \
185- strcmp((fname) + XLOG_FNAME_LEN, ".partial") == 0)
186-
187- #define XLogFromFileName (fname , tli , logSegNo , wal_segsz_bytes ) \
188- do { \
189- uint32 log; \
190- uint32 seg; \
191- sscanf(fname, "%08X%08X%08X", tli, &log, &seg); \
192- *logSegNo = (uint64) log * XLogSegmentsPerXLogId(wal_segsz_bytes) + seg; \
193- } while (0)
194-
195- #define XLogFilePath (path , tli , logSegNo , wal_segsz_bytes ) \
196- snprintf(path, MAXPGPATH, XLOGDIR "/%08X%08X%08X", tli, \
197- (uint32) ((logSegNo) / XLogSegmentsPerXLogId(wal_segsz_bytes)), \
198- (uint32) ((logSegNo) % XLogSegmentsPerXLogId(wal_segsz_bytes)))
199-
200- #define TLHistoryFileName (fname , tli ) \
201- snprintf(fname, MAXFNAMELEN, "%08X.history", tli)
202-
203- #define IsTLHistoryFileName (fname ) \
204- (strlen(fname) == 8 + strlen(".history") && \
205- strspn(fname, "0123456789ABCDEF") == 8 && \
206- strcmp((fname) + 8, ".history") == 0)
207-
208- #define TLHistoryFilePath (path , tli ) \
209- snprintf(path, MAXPGPATH, XLOGDIR "/%08X.history", tli)
210-
211- #define StatusFilePath (path , xlog , suffix ) \
212- snprintf(path, MAXPGPATH, XLOGDIR "/archive_status/%s%s", xlog, suffix)
213-
214- #define BackupHistoryFileName (fname , tli , logSegNo , startpoint , wal_segsz_bytes ) \
215- snprintf(fname, MAXFNAMELEN, "%08X%08X%08X.%08X.backup", tli, \
216- (uint32) ((logSegNo) / XLogSegmentsPerXLogId(wal_segsz_bytes)), \
217- (uint32) ((logSegNo) % XLogSegmentsPerXLogId(wal_segsz_bytes)), \
218- (uint32) (XLogSegmentOffset(startpoint, wal_segsz_bytes)))
219-
220- #define IsBackupHistoryFileName (fname ) \
221- (strlen(fname) > XLOG_FNAME_LEN && \
222- strspn(fname, "0123456789ABCDEF") == XLOG_FNAME_LEN && \
223- strcmp((fname) + strlen(fname) - strlen(".backup"), ".backup") == 0)
224-
225- #define BackupHistoryFilePath (path , tli , logSegNo , startpoint , wal_segsz_bytes ) \
226- snprintf(path, MAXPGPATH, XLOGDIR "/%08X%08X%08X.%08X.backup", tli, \
227- (uint32) ((logSegNo) / XLogSegmentsPerXLogId(wal_segsz_bytes)), \
228- (uint32) ((logSegNo) % XLogSegmentsPerXLogId(wal_segsz_bytes)), \
229- (uint32) (XLogSegmentOffset((startpoint), wal_segsz_bytes)))
191+ static inline bool
192+ IsPartialXLogFileName (const char * fname )
193+ {
194+ return (strlen (fname ) == XLOG_FNAME_LEN + strlen (".partial" ) &&
195+ strspn (fname , "0123456789ABCDEF" ) == XLOG_FNAME_LEN &&
196+ strcmp (fname + XLOG_FNAME_LEN , ".partial" ) == 0 );
197+ }
198+
199+ static inline void
200+ XLogFromFileName (const char * fname , TimeLineID * tli , XLogSegNo * logSegNo , int wal_segsz_bytes )
201+ {
202+ uint32 log ;
203+ uint32 seg ;
204+
205+ sscanf (fname , "%08X%08X%08X" , tli , & log , & seg );
206+ * logSegNo = (uint64 ) log * XLogSegmentsPerXLogId (wal_segsz_bytes ) + seg ;
207+ }
208+
209+ static inline void
210+ XLogFilePath (char * path , TimeLineID tli , XLogSegNo logSegNo , int wal_segsz_bytes )
211+ {
212+ snprintf (path , MAXPGPATH , XLOGDIR "/%08X%08X%08X" , tli ,
213+ (uint32 ) (logSegNo / XLogSegmentsPerXLogId (wal_segsz_bytes )),
214+ (uint32 ) (logSegNo % XLogSegmentsPerXLogId (wal_segsz_bytes )));
215+ }
216+
217+ static inline void
218+ TLHistoryFileName (char * fname , TimeLineID tli )
219+ {
220+ snprintf (fname , MAXFNAMELEN , "%08X.history" , tli );
221+ }
222+
223+ static inline bool
224+ IsTLHistoryFileName (const char * fname )
225+ {
226+ return (strlen (fname ) == 8 + strlen (".history" ) &&
227+ strspn (fname , "0123456789ABCDEF" ) == 8 &&
228+ strcmp (fname + 8 , ".history" ) == 0 );
229+ }
230+
231+ static inline void
232+ TLHistoryFilePath (char * path , TimeLineID tli )
233+ {
234+ snprintf (path , MAXPGPATH , XLOGDIR "/%08X.history" , tli );
235+ }
236+
237+ static inline void
238+ StatusFilePath (char * path , const char * xlog , const char * suffix )
239+ {
240+ snprintf (path , MAXPGPATH , XLOGDIR "/archive_status/%s%s" , xlog , suffix );
241+ }
242+
243+ static inline void
244+ BackupHistoryFileName (char * fname , TimeLineID tli , XLogSegNo logSegNo , XLogRecPtr startpoint , int wal_segsz_bytes )
245+ {
246+ snprintf (fname , MAXFNAMELEN , "%08X%08X%08X.%08X.backup" , tli ,
247+ (uint32 ) (logSegNo / XLogSegmentsPerXLogId (wal_segsz_bytes )),
248+ (uint32 ) (logSegNo % XLogSegmentsPerXLogId (wal_segsz_bytes )),
249+ (uint32 ) (XLogSegmentOffset (startpoint , wal_segsz_bytes )));
250+ }
251+
252+ static inline bool
253+ IsBackupHistoryFileName (const char * fname )
254+ {
255+ return (strlen (fname ) > XLOG_FNAME_LEN &&
256+ strspn (fname , "0123456789ABCDEF" ) == XLOG_FNAME_LEN &&
257+ strcmp (fname + strlen (fname ) - strlen (".backup" ), ".backup" ) == 0 );
258+ }
259+
260+ static inline void
261+ BackupHistoryFilePath (char * path , TimeLineID tli , XLogSegNo logSegNo , XLogRecPtr startpoint , int wal_segsz_bytes )
262+ {
263+ snprintf (path , MAXPGPATH , XLOGDIR "/%08X%08X%08X.%08X.backup" , tli ,
264+ (uint32 ) (logSegNo / XLogSegmentsPerXLogId (wal_segsz_bytes )),
265+ (uint32 ) (logSegNo % XLogSegmentsPerXLogId (wal_segsz_bytes )),
266+ (uint32 ) (XLogSegmentOffset ((startpoint ), wal_segsz_bytes )));
267+ }
230268
231269/*
232270 * Information logged when we detect a change in one of the parameters
0 commit comments